A reusable, modern PHP development environment powered by Docker, Nginx, PHP-FPM, MySQL, and phpMyAdmin — designed so you can clone this template and instantly start a new PHP project.
This template includes:
- Fully configured Docker development environment
- Isolated PHP container with configurable PHP version
- Automatic volume syncing to your local project
- MySQL + health checks + phpMyAdmin
- Nginx configured for a PHP project
- Makefile with common developer commands
- .env.example for easy configuration
- Optional code formatters (php-cs-fixer, pretty-php, phpcs) installed globally in the PHP container
project-root/
│
├── dev_env/
│ ├── docker-compose.base.yml
│ ├── php-env/
│ │ ├── Dockerfile
│ │ └── php.ini
│ └── nginx/
│ └── default.conf
│
├── public/
│ ├── index.php
│ └── test-db.php
│
├── src/
│ └── .gitkeep
│
├── .php-cs-fixer.php ← PHP-CS-Fixer configuration
├── docker-php-cs-fixer.sh ← Runs PHP-CS-Fixer inside Docker
├── .pre-commit-config.yaml ← Pre-commit hook configuration
│
├── composer.json
├── Makefile
├── .env.example
└── README.md
- Docker 24+
- Docker Compose V2
- GNU Make
- Git
git clone https://github.com/tresiab/php_dev_setup_template new-project
cd new-project(or use this repo as a GitHub Template)
cp .env.example .env(edit .env to match your setup)
make upContainers will build and run:
- PHP (8.2 by default)
- Nginx
- MySQL
- phpMyAdmin
http://localhost:8080
http://localhost:8081
Login using credentials from .env:
- User: MYSQL_USER
- Password: MYSQL_PASSWORD
| Service | Port | Description |
|---|---|---|
| Nginx | 8080 → 80 | Web server |
| php-fpm | internal | Executes PHP scripts |
| MySQL | 3306 → 3306 | Database server |
| phpMyAdmin | 8081 → 80 | DB admin UI |
The template includes a beginner-friendly composer.json:
{
"name": "yourname/php-project",
"description": "Starter PHP project template",
"type": "project",
"require": {
"php": "^8.2",
"vlucas/phpdotenv": "^5.5"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"require-dev": {
"symfony/var-dumper": "^7.0"
},
"scripts": {
"start": "php -S 0.0.0.0:8000 -t public",
"dump": "composer dump-autoload"
},
"config": {
"sort-packages": true
}
}Install dependencies:
make shell
git config --global --add safe.directory /var/www/html
composer install| Command | Description |
|---|---|
| make up | Build and start all containers |
| make down | Stop all containers |
| make logs | Show PHP container logs |
| make shell | Get a shell inside the PHP container |
| make db-shell | Open MySQL console inside DB container |
| make format | Run PHP formatters (php-cs-fixer + pretty-php) |
| make clean-volumes | Remove containers + volumes |
| make clean-images | Remove containers + images |
The template provides:
public/test-db.phpVisit:
http://localhost:8080/test-db.php
You should see:
Database connection successful!
If not, double-check your .env values.
After cloning the template:
- Edit .env
- Rename yourname/php-project in composer.json
- Add your code inside /src
- Add routes, controllers, templates, etc.
- Use /public for public-facing files
pre-commit install
pre-commit run --all-filesExample:
Bind for 0.0.0.0:8080 failed: port is already allocatedFix:
sudo lsof -i :8080
sudo kill <PID>Or change ports in .env:
PROJECT_PHP_PORT=8082
PROJECT_PMA_PORT=8083
Ensure .env loads inside Makefile:
export $(shell sed -E 's/=.*//' .env)Double-check:
echo $MYSQL_USER