An open API service indexing awesome lists of open source software.

https://github.com/arielespinoza07/php-dev-stack

๐Ÿณ A powerful Docker-based development environment for any PHP project โ€” supports multiple PHP versions (5.6โ€“8.3), Laravel, Symfony, WordPress, Nginx virtual hosts, MySQL, PostgreSQL, Redis, Node.js, and Supervisor queue workers. Designed for local development with WSL2/Linux/macOS.
https://github.com/arielespinoza07/php-dev-stack

dev-environment docker fullstack laravel makefile mysql nginx php postgresql redis supervisor symfony vite webpack wordpress

Last synced: about 1 month ago
JSON representation

๐Ÿณ A powerful Docker-based development environment for any PHP project โ€” supports multiple PHP versions (5.6โ€“8.3), Laravel, Symfony, WordPress, Nginx virtual hosts, MySQL, PostgreSQL, Redis, Node.js, and Supervisor queue workers. Designed for local development with WSL2/Linux/macOS.

Awesome Lists containing this project

README

          

# ๐Ÿ“ฆ 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:

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

### 2. Set PHP version in `.env`:

```dotenv
PHP_VERSION=8.3
```

### 3. Set database engine:

```dotenv
DB_CONNECTION=mysql# or pgsql
```

### 4. Enable a virtual host:

```bash
make enable-site site=api.local.conf
```

### 5. Add domains to `/etc/hosts`:

```plaintext
127.0.0.1 api.local
127.0.0.1 symfony.local
```

### 6. Start the stack:

```bash
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)](https://learn.microsoft.com/en-us/windows/wsl/install)
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:

```bash
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):

```bash
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](LICENSE)