Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.PHP extension in url download the php file instead of execution #1456

Closed
svarup opened this issue Oct 31, 2023 · 2 comments
Closed

.PHP extension in url download the php file instead of execution #1456

svarup opened this issue Oct 31, 2023 · 2 comments

Comments

@svarup
Copy link

svarup commented Oct 31, 2023

Steps to reproduce:

  1. create one directorytest
  2. create an index.php file inside test
<?php

echo 'Hello World';
  1. create a Dockerfile file inside test
FROM php:8.2.10-apache

WORKDIR /var/www/html
COPY . .
  1. create docker-compose.yaml file inside test
version: '3'
services:

  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: app
    container_name: app
    volumes:
      - ./:/var/www/html
    ports:
      - 80:80

in the above docker-compose.yaml file, we attach the local current directory test to the docker folder /var/www/html using volumes. This will allow the local changes we made in test directory during development will be sync to the docker image.

now run docker-compose up and visit localhost/index.php you can see the output Hello World, but if you visit localhost/index.PHP then it will show blank page(you can see the php source code using view source), or it will download php file.

if we remove the volumes part from the docker-compose.yaml file then it works as expected, it gives an apache default 404 error page on visiting localhost/index.PHP

version: '3'
services:

  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: app
    container_name: app
#    volumes:
#      - ./:/var/www/html
    ports:
      - 80:80
@LaurentGoderre
Copy link
Member

That's because apache by default is case sensitive and the mapping for php is only for .php and not .PHP. You can solve you problem quite easily with sluign modifications.

Dockerfile:

FROM php:8.2.10-apache

RUN a2enmod speling

WORKDIR /var/www/html
COPY . .

Create an .htaccess

# Allow mixed case requests (mod_speling)
CheckSpelling on
CheckCaseOnly on

Now when accessing index.PHP it goes to index.php

@tianon
Copy link
Member

tianon commented Nov 30, 2023

Duplicate of #973

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants