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'
services:
nginx:
build:
context: .
dockerfile: dockerfile
depends_on:
- php
volumes:
- ./html:/var/www/html
networks:
- nginx:php-net
ports:
- 8000:80
php:
image: php:fpm-alpine
networks:
- nginx:php-net
networks:
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 {
listen 0.0.0.0:80;
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.
- 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.
- 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.
- 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