This repository provides a ready-to-run Docker environment for a PHP web application using:
- PHP 8.5 FPM (Alpine)
- Nginx (stable-alpine)
- MySQL 8.4
It is framework-agnostic and points the web root to src/public by default.
- Copy environment file and adjust if needed:
cp .env.example .env
- Build and start the stack:
docker compose up -d --build
- Open the app in your browser:
- http://localhost:8080 (or the port you set in
APP_PORT)
You should see a simple PHP page, and (once MySQL is ready) database connectivity information.
.
├─ docker-compose.yml
├─ .env.example (copy to .env)
├─ docker/
│ ├─ php/
│ │ └─ Dockerfile
│ └─ nginx/
│ └─ default.conf
└─ src/
└─ public/
└─ index.php
- Web root (document root):
src/public - PHP container working dir:
/var/www/html
- Image:
php:8.4-fpm-alpine(built locally with common extensions) - Composer is available inside the container (
/usr/local/bin/composer).
Run Composer inside the PHP container (recommended for consistent platform):
docker compose exec php composer --version
# or install deps
# docker compose exec php composer install
- Image:
nginx:stable-alpine - Serves
src/publicand forwards*.phptophp:9000(FPM). - Default vhost config at
docker/nginx/default.conf.
- Image:
mysql:8.4 - Data persisted in named volume
mysql_data. - Connection from PHP: host
mysql, port3306, credentials from.env/docker-compose.yml.
Connect to MySQL from host:
docker compose exec mysql mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE
APP_PORT(default:8080) — published HTTP portMYSQL_DATABASE(default:app)MYSQL_USER(default:app)MYSQL_PASSWORD(default:app)MYSQL_ROOT_PASSWORD(default:root)MYSQL_PORT(default:3306)
Set them in .env or edit docker-compose.yml directly.
- The Nginx config expects your application’s public files (including
index.php) insrc/public. - For Laravel/Symfony and similar frameworks, point the document root here without modifications.
- The MySQL container has a healthcheck; the PHP page may show DB connection errors briefly until MySQL is ready — this is normal on first startup.
- If you need more PHP extensions, edit
docker/php/Dockerfileand rebuild:docker compose build php && docker compose up -d.
Stop and remove containers (data volume preserved):
docker compose down
Remove containers and the MySQL data volume:
docker compose down -v