Docker Community Forums

Share and learn in the Docker community.

Why is my PHPmyAdmin site running, but my PHP files wont?

Hey.
When I run this docker-compose file:

web:
    image: nginx:latest
    restart: always
    ports:
        - "8080:80"
    volumes:
        - ./code:/code
        - ./site.conf:/etc/nginx/conf.d/site.conf
    links:
        - php
php:
    image: php:7-fpm
    restart: always
    volumes:
        - ./code:/code
db:
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: admin
phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: admin    
    ports:
    - "6001:80"
    volumes:
    - /sessions
    - ~/docker/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
    - /custom/phpmyadmin/theme/:/www/themes/theme/

It will load my phpMyAdmin container, however when I curl my localhost:8080, I see the default nginx page, when I have a code/index.php file.
Here is my NGINX site.conf:

server {
index index.php;
server_name php-docker.local;
error_log  /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

You are following a tutorial from 2016. I recommend that you use a php image that contains a web server, like php:apache-buster and read the docs of the php image, especially the section ‘Image Variants’.