A reusable Docker development environment for PHP web applications with Apache, MySQL, Redis, and additional development tools.
- Multi-stage Docker builds with optimized configurations for different environments
- PHP 8.4 with Apache and SSL support
- MySQL 9.3 database server
- Redis for caching and session storage
- Mailpit for email testing during development
- phpRedisAdmin for Redis management
- Environment-specific configurations (local, test, production)
- Hot-reload development with volume mounting
- XDebug integration for PHP debugging
.docker/
├── .env # Environment variables
├── .gitignore # Git ignore rules
├── docker-compose.yml # Main Docker Compose configuration
├── bin/
│ └── start # Environment startup script
└── website/
├── Dockerfile # Multi-stage PHP application Dockerfile
└── default-ssl.conf # Apache SSL virtual host configuration
- Docker Engine 20.10+
- Docker Compose 2.0+
-
Copy the
.dockerfolder to your project root:cp -r .docker /path/to/your/project/ cd /path/to/your/project/.docker -
Configure environment variables:
cp .env.example .env # If you have an example file # Or edit .env directly with your project-specific values
-
Create required directories:
mkdir -p ../.storage/mysql_server mkdir -p ../.storage/redis_server
-
Start the environment:
chmod +x bin/start ./bin/start local
| Variable | Description | Default |
|---|---|---|
WEBSITE_UI_PORT |
Port for web application | 8080 |
WEBSITE_ENVIRONMENT |
Build target (local/test/production) | local |
MYSQL_DEFAULT_DATABASE |
MySQL database name | app |
MYSQL_ROOT_PASSWORD |
MySQL root password | secret |
MYSQL_USER |
MySQL application user | app |
MYSQL_PASSWORD |
MySQL application password | secret |
MAILPIT_WEB_UI_PORT |
Mailpit web interface port | 8025 |
PHPREDISADMIN_WEB_UI_PORT |
phpRedisAdmin port | 7379 |
- Image: Custom multi-stage build
- Port: Configured via
WEBSITE_UI_PORT(default: 8080) - Features: PHP 8.4, Apache, SSL, XDebug (local), Node.js
- Volume:
../website:/var/www/html(development mode)
- Image:
mysql:9.3 - Port: 3306 (internal)
- Storage: Persistent volume at
../.storage/mysql_server
- Image:
redis:latest - Port: 6379 (internal)
- Storage: Persistent volume at
../.storage/redis_server
- Image:
axllent/mailpit - Port: Configured via
MAILPIT_WEB_UI_PORT(default: 8025) - Purpose: Capture and view emails during development
- Image:
actency/docker-phpredisadmin - Port: Configured via
PHPREDISADMIN_WEB_UI_PORT(default: 7379) - Purpose: Redis database management interface
The Dockerfile includes multiple stages optimized for different use cases:
- PHP 8.4 with Apache
- Essential PHP extensions (PDO, MySQL, Redis, GD, etc.)
- Composer installation
- SSL certificate generation
- Adds OPcache for production optimization
- Inherits from base stage
- Optimized for production deployment
- Includes Node.js for asset compilation
- No development tools
- Extends production stage
- Includes XDebug with coverage mode
- Ideal for CI/CD testing
- Development-optimized configuration
- XDebug with debug mode
- OPcache disabled for immediate code changes
- VSCode debugging support
- Background job processing
- Runs Laravel queue workers
- Minimal footprint
- Cron job replacement
- Runs Laravel scheduler
- Handles scheduled tasks
# Local development (default)
./bin/start local
# Testing environment
./bin/start test
# Production environment
./bin/start production- Web Application: https://localhost:8080 (or your configured port)
- Mailpit: http://localhost:8025
- phpRedisAdmin: http://localhost:7379
- MySQL: localhost:3306 (from host)
- Redis: localhost:6379 (from host)
# View running containers
docker-compose ps
# View logs
docker-compose logs -f website
# Access container shell
docker-compose exec website bash
# Stop all services
docker-compose down
# Rebuild and start
docker-compose up --build -dEnsure your project has the following structure:
your-project/
├── .docker/ # This Docker configuration
├── website/ # Your web application code
│ └── public/ # Web server document root
└── .storage/ # Persistent data storage
├── mysql_server/
└── redis_server/
Edit .docker/.env to match your project requirements:
- Update database credentials
- Change port numbers if needed
- Modify application environment
The Dockerfile is designed for PHP applications but can be customized:
- Add additional PHP extensions
- Include project-specific dependencies
- Modify Apache configuration
Edit .docker/website/default-ssl.conf:
- Change document root if needed
- Add custom virtual host settings
- Modify SSL configuration
For local development, XDebug is configured to work with VSCode:
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internalAdd to your .vscode/launch.json:
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}/website"
}
}- Environment Isolation: Always use environment-specific configurations
- Data Persistence: Use named volumes for database storage
- Security: Never commit
.envfiles with production credentials - Performance: Use production stage for deployment
- Development: Use local stage with volume mounting for development
- Port conflicts: Change ports in
.envif already in use - Permission issues: Ensure Docker has access to project directories
- SSL warnings: Accept self-signed certificate for local development
- Database connection: Verify MySQL service is running and credentials are correct
# Check all service logs
docker-compose logs
# Monitor specific service
docker-compose logs -f mysql_server
# Check container health
docker-compose psThis Docker configuration is designed to be reusable across multiple projects. Feel free to modify and adapt according to your needs.
When adapting this configuration for new projects:
- Test the setup thoroughly
- Document any project-specific modifications
- Update environment variables appropriately
- Ensure security best practices are followed
For questions or improvements, please refer to the project documentation or create an issue.