docker-library / php

Docker Official Image packaging for PHP
https://php.net
MIT License
3.84k stars 2.01k forks source link

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

Closed svarup closed 11 months ago

svarup commented 1 year ago

Steps to reproduce:

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

echo 'Hello World';

3. create a ```Dockerfile``` file inside ```test```

FROM php:8.2.10-apache

WORKDIR /var/www/html COPY . .

4. create ```docker-compose.yaml``` file inside ```test```

version: '3' services:

app: build: context: . dockerfile: Dockerfile image: app container_name: app volumes:

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 commented 1 year ago

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 commented 11 months ago

Duplicate of https://github.com/docker-library/php/issues/973