A Professional, Feature-Rich Docker Development Stack for Laravel
Streamline your Laravel development with multi-PHP support, modern tooling, and zero-configuration setup
The Laravel Docker Development Environment is a comprehensive, production-ready Docker stack designed specifically for Laravel developers. Whether you're maintaining legacy applications on PHP 7.x or building cutting-edge projects with PHP 8.3, this environment provides everything you need in a single, unified workspace.
- π Zero Configuration: Get up and running in under 5 minutes
 - π Multi-PHP Ready: All PHP versions (7.0-8.3) in one container
 - π Performance Optimized: Designed for speed and efficiency
 - π¦ Modular Architecture: Enable only the services you need
 - π οΈ Developer-Focused: Built by developers, for developers
 
 
  | 
 
  | 
Ensure you have these installed:
- π Docker Engine 20.10+
 - π§ Docker Compose 2.0+
 - π οΈ Make utility (
sudo apt install makeon Ubuntu) - π¦ Git
 
# Clone the repository
git clone https://github.com/alizaynoune/Laravel-Docker-DevEnv.git
cd Laravel-Docker-DevEnv
# Initialize environment (creates .env and sitesMap.yaml)
make installnano .envEssential settings:
# Your Laravel projects directory
APP_DIR=${HOME}/Code
# Services (enable/disable as needed)
ENABLE_MYSQL=true
ENABLE_PHPMYADMIN=true
ENABLE_REDIS=true
ENABLE_MAILHOG=true
# Database credentials
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=laravel
MYSQL_USERNAME=docker
MYSQL_PASSWORD=docker
# Default PHP version
DEFAULT_PHP=8.3nano sitesMap.yamlExample configuration:
sites:
    # Modern Laravel 10+ application
    - map: myapp.local
      to: myapp/public
      php: "8.3"
    # Legacy application
    - map: legacy-app.local
      to: legacy-project/public
      php: "7.4"
    # API project
    - map: api.local
      to: api-service/public
      php: "8.2"# Generate services and start containers
make upAdd your domains to /etc/hosts:
echo "127.0.0.1 myapp.local legacy-app.local api.local" | sudo tee -a /etc/hostsπ Web Applications:
- Your apps: 
http://myapp.local,http://legacy-app.local - PHPMyAdmin: 
http://phpmyadmin.local(if configured) 
π οΈ Development Tools:
- MailHog: 
http://localhost:8025 - Workspace SSH: 
ssh docker@localhost -p 2222 
π You're ready to develop!
The workspace container is your main development environment:
# Primary access method
make workspace
# Alternative SSH access
ssh docker@localhost -p 2222
# Execute commands directly
make exec workspace "php artisan --version"Switch between PHP versions instantly:
# Inside the workspace container
php70    # Switch to PHP 7.0
php74    # Switch to PHP 7.4
php81    # Switch to PHP 8.1
php82    # Switch to PHP 8.2
php83    # Switch to PHP 8.3
# Check current version
php --version
# List all available versions
php-versions# Core commands
make up              # Start all services
make down            # Stop and remove containers
make restart         # Restart all containers
make status          # Show detailed status
make logs            # Show all logs
make logs mysql      # Show specific service logs
# Service access
make workspace       # Access main development environment
make mysql           # MySQL console
make redis           # Redis console# MySQL console access
make mysql
# Connect from workspace
mysql -h mysql -u docker -p
# Database management via PHPMyAdmin
# http://phpmyadmin.local (configure in sitesMap.yaml)Perfect for testing email functionality:
Laravel configuration (.env):
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=nullAccess: http://localhost:8025
sites:
    - map: domain.local         # Local domain (add to /etc/hosts)
      to: project/public        # Path relative to APP_DIR
      php: "8.3"                # PHP version to use
    # Multiple domains for same project
    - map: app.local
      to: myapp/public
      php: "8.2"
    - map: www.app.local
      to: myapp/public
      php: "8.2"Supported PHP Versions:
7.0 β’ 7.1 β’ 7.2 β’ 7.3 β’ 7.4 β’ 8.0 β’ 8.1 β’ 8.2 β’ 8.3
| Variable | Description | Default | 
|---|---|---|
APP_DIR | 
Host directory containing your projects | ${HOME}/Code | 
DESTINATION_DIR | 
Container mount point | /var/www | 
USER_NAME | 
Container username | docker | 
USER_PASSWORD | 
Container password | docker | 
DEFAULT_PHP | 
Default PHP version | 8.3 | 
ENABLE_MYSQL | 
Enable MySQL service | false | 
ENABLE_PHPMYADMIN | 
Enable PHPMyAdmin | false | 
ENABLE_REDIS | 
Enable Redis service | false | 
ENABLE_MAILHOG | 
Enable MailHog service | false | 
MYSQL_ROOT_PASSWORD | 
MySQL root password | root | 
MYSQL_DATABASE | 
Default database | laravel | 
WORKSPACE_SSH_PORT | 
SSH port for workspace | 2222 | 
TZ | 
Timezone | UTC | 
Laravel-Docker-DevEnv/
βββ π README.md                    # This documentation
βββ π docker-compose.yml           # Core services configuration
βββ π docker-compose.override.yml  # Auto-generated optional services
βββ π Makefile                     # Management commands
βββ π .env                         # Environment configuration
βββ π sitesMap.yaml                # Sites and domains configuration
βββ π docker/                      # Docker configurations
β   βββ π³ workspace.Dockerfile     # Multi-PHP workspace
β   βββ π nginx/                   # Nginx configurations
β   βββ π supervisor/              # Process management
β   βββ π scripts/                 # Utility scripts
β   βββ π db/                      # Database configurations
βββ π scripts/                     # Management scripts
    βββ π docker-compose-generator.sh
    βββ π project-status.sh
Enable or disable services by modifying .env:
# Disable unnecessary services for lighter setup
ENABLE_MYSQL=false
ENABLE_PHPMYADMIN=false
ENABLE_REDIS=true
ENABLE_MAILHOG=true
# Regenerate services
make generate-services
make upAdd extensions in docker/workspace.Dockerfile:
RUN apt-get install -y \
    php8.3-extension-name \
    php8.2-extension-name \
    php8.1-extension-nameModify docker/nginx/nginx.conf for advanced web server settings.
# Comprehensive project status
make project-status
# Container resource usage
docker stats
# Service health checks
make statusπ« Port Conflicts
Problem: Ports 80, 443, or 3306 are already in use.
Solution:
# Check what's using the ports
sudo netstat -tulpn | grep :80
sudo netstat -tulpn | grep :3306
# Stop conflicting services
sudo systemctl stop apache2
sudo systemctl stop mysql
sudo systemctl stop nginxπ Site Not Loading
Problem: Your Laravel app shows 404 or doesn't load.
Solution:
- 
Check
/etc/hostsentry:grep myapp.local /etc/hosts
 - 
Ensure document root exists:
ls -la ${APP_DIR}/myapp/public 
π Permission Issues
Problem: Permission denied errors.
Solution:
# Check your user ID
id
# Update .env with correct values
USER_UID=$(id -u)
USER_GID=$(id -g)
# Rebuild containers
make build
make upπ PHP Version Not Working
Problem: PHP version switching fails.
Solution:
# Access workspace and check available versions
make workspace
php-versions
# Manually switch version
sudo update-alternatives --config phpIf you need to start fresh:
# Nuclear option - removes everything
make clean
# Rebuild from scratch
make build
make up# Morning startup
make up
make workspace
# Work on your project
cd /var/www/myproject
php83  # Switch to PHP 8.3
composer install
php artisan migrate:fresh --seed
# Test with different PHP versions
php74  # Switch to PHP 7.4 for compatibility testing
vendor/bin/phpunit
# End of day (optional)
exit
make stop# Access workspace
make workspace
# Create new Laravel project
cd /var/www
composer create-project laravel/laravel new-project
cd new-project
# Set up environment
cp .env.example .env
php artisan key:generate
# Configure database connection
php artisan migrate# Clone your existing project to APP_DIR
git clone https://github.com/your/legacy-project.git ${APP_DIR}/legacy-project
# Add to sitesMap.yaml
echo "
    - map: legacy.local
      to: legacy-project/public
      php: \"7.4\"
" >> sitesMap.yaml
# Add to hosts file
echo "127.0.0.1 legacy.local" | sudo tee -a /etc/hosts
# Restart to apply changes
make restart# Inside workspace
make workspace
# Run tests across PHP versions
php81
composer test
php82
composer test
php83
composer test
# Code quality
composer run-script phpstan
composer run-script phpcs- 
Resource Allocation:
# Monitor resource usage docker stats # Adjust Docker Desktop resources if needed # Recommended: 4GB RAM, 2 CPUs minimum
 - 
Volume Optimization:
- Use bind mounts for development (default setup)
 - Consider named volumes for database data in production
 
 - 
Service Management:
- Disable unused services in 
.env - Use 
make generate-servicesafter changes 
 - Disable unused services in 
 
# Remove unused Docker resources
make prune
# Check disk usage
docker system df
# Clean up everything (nuclear option)
docker system prune -a --volumesWe welcome contributions! Here's how you can help:
# Fork the repository on GitHub
git clone https://github.com/your-username/Laravel-Docker-DevEnv.git
cd Laravel-Docker-DevEnv
# Create feature branch
git checkout -b feature/amazing-feature
# Make your changes and test
make up
make workspace
# Commit and push
git commit -m "Add amazing feature"
git push origin feature/amazing-feature- Bug Reports: Use GitHub Issues with detailed reproduction steps
 - Feature Requests: Discuss in Issues before implementing
 - Code Style: Follow existing patterns and conventions
 - Testing: Ensure changes work across PHP versions
 - Documentation: Update README for new features
 
Thanks to all contributors who have helped improve this project!
This project is licensed under the MIT License - see the LICENSE file for details.
- β Commercial use
 - β Modification
 - β Distribution
 - β Private use
 - β Liability
 - β Warranty
 
- π Bug Reports: GitHub Issues
 - π‘ Feature Requests: GitHub Discussions
 - π Documentation: This README and inline code comments
 - π¬ Community: Share experiences and help others
 
Special thanks to:
- π Laravel Team - For the amazing framework that powers modern PHP development
 - π Docker Team - For revolutionizing application containerization
 - π Nginx Team - For the high-performance web server
 - π PHP Team - For the continuous evolution of the language
 - π₯ Open Source Community - For countless tools and inspirations
 - π All Contributors - Who have helped improve this project
 
git clone https://github.com/alizaynoune/Laravel-Docker-DevEnv.git
cd Laravel-Docker-DevEnv
make install
make up
make workspaceβ Star this repo if it helped you!
π’ Share with your team and colleagues
π€ Contribute to make it even better
Built with β€οΈ by developers, for developers
Happy Coding! π―