How-to's Setup PHP development environment with Docker
1. Create the project directory
  1. mkdir docker-php
2. Create a docker-compose.yml file with the following configuration to define the services
/docker-php/docker-compose.yml
services:
    php:
        build:
            context: .
            dockerfile: Dockerfile
        container_name: docker-php
        volumes:
            - .:/usr/share/nginx/html/docker-php
        networks:
            - docker-php
    nginx:
        image: nginx:latest
        container_name: docker-nginx
        ports:
            - 80:80
        volumes:
            - ./nginx.conf:/etc/nginx/conf.d/default.conf
            - .:/usr/share/nginx/html/docker-php
        networks:
            - docker-php
networks:
    docker-php:
        driver: bridge
3. Create a Dockerfile to define the PHP environment
/docker-php/Dockerfile
FROM php:8.3-fpm
WORKDIR /usr/share/nginx/html/docker-php
4. Create a nginx.conf file to configure Nginx to work with PHP-FPM
/docker-php/nginx.conf
server {
    listen       80;
    listen  [::]:80;
    root   /usr/share/nginx/html/docker-php/public;
    index  index.php index.html index.htm;

    location ~ .php$ {
        fastcgi_pass   php:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
5. Create a simple PHP file to verify the setup
/docker-php/public/index.php
<?php phpinfo(); ?>
6. Start all Docker containers in the background
  1. docker compose up -d
[+] Running 3/3
 ✔ Network docker-php_docker-php  Created                           0.9s
 ✔ Container docker-nginx         Started                           1.7s
 ✔ Container docker-php           Started                           1.7s
7. Navigate to http://127.0.0.1 and you should see the detailed information about the PHP configuration