Docker nginx and php-fpm "File Not Found"

Hello there,
I’ve just started with docker and I know just the basics. I’ve recently tried to create a docker-compose file for nginx and php-fpm, to get php files to work. Ive tried mapping ports for nginx and php and to create a docker network. This is the docker-compose.yml:

version: '3.8'
      context: .
      dockerfile: dockerfile
      - php
      - ./html:/var/www/html
      - nginx:php-net
      - 8000:80

    image: php:fpm-alpine
      - nginx:php-net

    driver: bridge

My file system is just the /html folder with an index.php in it. I have also created an dockerfile:

FROM nginx:latest
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf

to overwrite the default.conf. Then nginx.conf in my folder is just the basic implementations for php-fpm:

server {
    root /var/www/html;
    location / {
        index index.php index.html;
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

When I do “docker-compose -d up” it stats both services and localhost:8000 is working, when I include a index.html for example. But if I try to acces a .php file, It returns a page saying “File not found”.
I’ve looked it up and there are 3 main reasons, why this could happen.

  1. Wrong parameters like a path doesn’t exist. Unfortunally I have no idea which paths to check here so I hoped that anyone could help me with that.
  2. Permissions Ive checked my nginx folders and everythin has root rw permissions so I don’t think that is the reason for my problem but correct me if I’m wrong.
  3. php is not running. I can surely exclude that point, because I see my docker php:fpm-alpine container running.
    I hope someone knows what my mistake is and explain it to me.
    Thank you in advanced :slight_smile:

For all those who run into the same problem:
In my case, I forgot to map the volume from php-fpm to my html folder. The php section in the docker-copmpose.yml should look like this:

    image: php:fpm-alpine
      - nginx:php-net
      - ./html/:/var/www/html/
      - ./logs/php.log:/var/log/fpm-php.www.log

1 Like