A comprehensive Docker-based WordPress development and deployment environment using WordPress, Docker, PHP-FPM 8.3, MySQL 8.4, Nginx, Redis, and Traefik.
- WordPress: Latest version with PHP-FPM 8.3
- MySQL 8.4: Database server
- Nginx: Web server
- Redis: Object caching
- Traefik: Reverse proxy with SSL/TLS support (dev/prod)
- WP-CLI: Command-line interface for WordPress management
- OPcache: PHP optimization with fine-tuned settings
This stack features a comprehensive WP-CLI integration that streamlines WordPress management:
- WordPress core installation and updates via WP-CLI
- Automated site configuration and initial setup
- Customizable default theme installation
- Built-in Redis cache plugin integration
- Optimized permalink structure setup
- Removal of unnecessary default plugins/themes
- Database backup and restore functionality
The stack includes optimized PHP configurations for maximum WordPress performance:
- OPcache: Bytecode caching to speed up PHP execution
- PHP-FPM Pool: Optimized process manager settings for better resource usage
- Custom PHP Settings: Tailored PHP configurations for WordPress workloads
- JIT Compilation: PHP 8.4 JIT enabled for additional performance
- File Caching: Secondary caching layer for OPcache
- Redis Object Cache: Integration with WordPress object caching
These optimizations significantly improve WordPress performance, especially under heavy load.
.
├── backups/ # Database backups
├── config/ # Configuration files
│ ├── nginx/ # Nginx configuration
│ │ └── default.conf # Default Nginx config
│ └── php/ # PHP configuration files
│ ├── www.conf # PHP-FPM pool configuration
│ ├── opcache.ini # OPcache settings
│ └── custom.ini # Additional PHP settings
├── letsencrypt/ # Let's Encrypt certificates (created on first run)
├── scripts/ # Management scripts
│ └── manage.sh # Main management script
├── wordpress/ # WordPress source code
│ ├── Dockerfile # WordPress container definition
│ ├── docker-entrypoint.sh # Container initialization script
│ ├── wp-cli.yml # WP-CLI configuration
│ ├── themes/ # WordPress themes
│ ├── plugins/ # WordPress plugins
│ └── wp-cli-packages/ # WP-CLI packages
├── .env # Environment variables (copy from .env.example)
├── .env.example # Example environment variables
├── docker-compose.yml # Base Docker Compose configuration
├── docker-compose.local.yml # Local environment configuration
├── docker-compose.dev.yml # Development environment configuration
└── docker-compose.prod.yml # Production environment configuration
-
Copy environment variables file:
cp .env.example .env
-
Edit environment variables: Open
.envin your editor and customize as needed. -
Start the environment:
# For local development ENVIRONMENT=local ./scripts/manage.sh start # For development environment ENVIRONMENT=dev ./scripts/manage.sh start # For production environment ENVIRONMENT=prod ./scripts/manage.sh start
When running in the local development environment, non-standard ports are used to avoid conflicts:
| Service | Standard Port | Local Port | URL/Connection String |
|---|---|---|---|
| WordPress | 80 | 8080 | http://localhost:8080 |
| MySQL | 3306 | 33060 | mysql://localhost:33060 |
| Redis | 6379 | 63790 | redis://localhost:63790 |
These non-standard ports help prevent conflicts with other services you might be running on your development machine.
The management script provides the following commands:
ENVIRONMENT=<local|dev|prod> ./scripts/manage.sh <command>Available commands:
start: Start all servicesstop: Stop all servicesrestart: Restart all serviceslogs: View logspull: Update code from git and rebuildstatus: Check container statuswp: Run WP-CLI commandsshell: Access the WordPress container shelldb-backup: Create a database backupdb-restore: Restore a database from backup
The stack includes WP-CLI for managing WordPress from the command line:
# List installed plugins
ENVIRONMENT=local ./scripts/manage.sh wp plugin list
# Update all plugins
ENVIRONMENT=local ./scripts/manage.sh wp plugin update --all
# Install a theme
ENVIRONMENT=local ./scripts/manage.sh wp theme install twentytwentytwo
# Create a new user
ENVIRONMENT=local ./scripts/manage.sh wp user create john john@example.com --role=author
# Export/import content
ENVIRONMENT=local ./scripts/manage.sh wp export > export.xml
ENVIRONMENT=local ./scripts/manage.sh wp import export.xml --authors=create
# Update WordPress core
ENVIRONMENT=local ./scripts/manage.sh wp core update
ENVIRONMENT=local ./scripts/manage.sh wp core update-db
# Manage media
ENVIRONMENT=local ./scripts/manage.sh wp media regenerate --yes# Create a database backup
ENVIRONMENT=local ./scripts/manage.sh db-backup
# Restore a database from backup
ENVIRONMENT=local ./scripts/manage.sh db-restore backups/backup-20230101120000.sql- Clone the repository
- Start the local environment
- Develop in the
wordpressdirectory (themes, plugins, etc.) - Git commit your changes
- Deploy to dev/prod using the management script
- Sensitive configuration is separated from source code
- Production environment uses SSL/TLS encryption
- Nginx configuration blocks access to sensitive files
- Environment variables store passwords and secrets
- WordPress security keys are auto-generated