Skip to content

ArielEspinoza07/php-dev-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ PHP Dockerized Environment with Multi-Version, Multi-Framework & Virtual Host Support

Build - PHP images CI - Core Validation Lint - Dockerfile & Makefile Framework - Laravel / Symfony Test License

This repository provides a robust and flexible development setup for any PHP-based project (Laravel, Symfony, WordPress, etc.) using Docker, with full support for:

  • βœ… Multiple PHP versions (5.6, 7.4–8.3)
  • βœ… Virtual host management via sites-available / sites-enabled
  • βœ… Composer and Xdebug (where supported)
  • βœ… MySQL or PostgreSQL selectable per project
  • βœ… Redis support
  • βœ… Node.js support for frontend tools (Vite, Webpack, etc.)
  • βœ… Supervisor integration for queue workers
  • βœ… Centralized Makefile for streamlined DX
β”œβ”€β”€ data/                        # Volumes (mysql, pgsql, redis)
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ nginx/
β”‚   β”‚   β”œβ”€β”€ nginx.conf
β”‚   β”‚   β”œβ”€β”€ sites-available/    # Contains available vhosts
β”‚   β”‚   └── sites-enabled/      # Contains symlinks to enabled vhosts
β”‚   β”œβ”€β”€ php/
β”‚   β”‚   β”œβ”€β”€ entrypoint.sh
β”‚   β”‚   └── [5.6 | 7.4 | 8.0 | 8.3]/ β†’ Dockerfile + php.ini
β”‚   └── supervisor/
β”‚       └── supervisord.conf
β”œβ”€β”€ logs/                       # Logs from services (e.g., nginx)
β”œβ”€β”€ src/                        # Where your PHP projects live
β”œβ”€β”€ docker-compose.yml          # Core services (nginx, php, node, redis)
β”œβ”€β”€ docker-compose.mysql.yml    # Optional MySQL stack
β”œβ”€β”€ docker-compose.pgsql.yml    # Optional PostgreSQL stack
β”œβ”€β”€ Makefile                    # Dev command runner

πŸš€ Getting Started

1. Clone this boilerplate:

cp -r this-folder my-new-project
cd my-new-project
cp .env.example .env

2. Set PHP version in .env:

PHP_VERSION=8.3

3. Set database engine:

DB_CONNECTION=mysql# or pgsql

4. Enable a virtual host:

make enable-site site=api.local.conf

5. Add domains to /etc/hosts:

127.0.0.1 api.local
127.0.0.1 symfony.local

6. Start the stack:

make up-db         # Auto-detects DB from .env

βš™οΈ Useful Makefile Commands

Command Description
make up Start default stack (nginx, php, redis)
make up-mysql Start stack with MySQL
make up-pgsql Start stack with PostgreSQL
make up-db Detects DB from .env and runs accordingly
make down Stop and remove containers
make restart Restart stack
make switch-php version=8.2 Change PHP version
make logs Tail container logs
make bash Open shell in PHP container
make composer-create-project project=... name=... Run composer install
make composer-install project=... Run composer install
make composer-update project=... Run composer update
make composer-require project=... package=... Install package via Composer
make run-php-command project=... command=... Run any PHP CLI command
make run-npm-command project=... command=... Run any npm command (install, run dev, etc.)
make enable-site site=... Enable virtual host
make new-site site=... Create + enable new virtual host

⚠️ Windows Support

This development environment is designed for Linux/macOS or Windows with WSL2.

βœ… Recommended for Windows users

To use this setup on Windows, follow these steps:

  1. Install WSL2 (Windows Subsystem for Linux)
  2. Install a Linux distribution (Ubuntu is recommended)
  3. Ensure Docker Desktop is installed and configured to use WSL2
  4. Open a WSL terminal and use make commands as usual:
   make up-db
   make switch-php version=8.2
   make run-php-command command="artisan migrate"

πŸ› οΈ Manual fallback (if not using WSL)

If you can't use WSL2, you may run equivalent commands manually from Git Bash or CMD (limited support):

docker compose -f docker-compose.yml -f docker-compose.mysql.yml up -d --build
docker exec -it php_project_php bash
composer install
⚠️ Note: Some Makefile logic (like sed, ln -sf, conditional execution) won't work on Windows without WSL2.

For full compatibility, WSL2 is strongly recommended.


πŸ§ͺ PHP Version Support

Version Composer Xdebug Notes
5.6 ❌ ❌ Legacy, limited
7.4 βœ… βœ… Stable, supported
8.0+ βœ… βœ… Recommended for new projects

🧠 Notes

  • Node is available for projects using modern frontend tooling (Vite, Webpack, etc.)
  • Supervisor is integrated and can be configured via .env to run queue workers.
  • Redis is included and exposed for local debugging and pub/sub dev scenarios.
  • Ports for Node (e.g., Vite) are optional and can be configured dynamically.

πŸ“œ License

MIT License

About

🐳 Docker-based dev environment for any PHP project. Supports PHP 5.6–8.4, Laravel, Symfony, WordPress, Nginx, MySQL, PostgreSQL, Redis, Node.js, Supervisor. For WSL2/Linux/macOS.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages