This is a Docker-based development environment for WordPress, featuring MySQL, phpMyAdmin, and Nginx Proxy Manager.
-
Environment Configuration
cp .env.sample .env
Edit
.env
with your preferred settings:IP
: Local IP address (default: 127.0.0.1)PORT
: WordPress port (default: 8000)DB_NAME
: Database name (default: wordpress)DB_ROOT_PASSWORD
: MySQL root password (default: somewordpress)
-
Start MySQL First
docker-compose up -d db
Wait a few seconds for MySQL to initialize completely.
-
Start WordPress and Nginx Proxy
docker-compose up -d wp proxy
This will start:
- WordPress at http://127.0.0.1:8000 (or your configured IP:PORT)
- Nginx Proxy Manager at http://127.0.0.1:81
- Main site: http://127.0.0.1:8000 (or your configured IP:PORT)
- Admin panel: http://127.0.0.1:8000/wp-admin
- Access at: http://127.0.0.1:8080
- Login with:
- Server: db
- Username: root
- Password: (your DB_ROOT_PASSWORD from .env)
- Admin UI: http://127.0.0.1:81
- Default login:
- Email: [email protected]
- Password: changeme
- Setting up Reverse Proxy
WP-CLI is included for WordPress management. Here are some common commands:
-
Update WordPress Core
docker-compose run --rm wpcli core update
-
Update Themes
# List themes docker-compose run --rm wpcli theme list # Update all themes docker-compose run --rm wpcli theme update --all # Update specific theme docker-compose run --rm wpcli theme update theme-name
-
Update Plugins
# List plugins docker-compose run --rm wpcli plugin list # Update all plugins docker-compose run --rm wpcli plugin update --all
.
├── wordpress/
│ ├── wp-app/
│ │ ├── wp-config.php
│ │ └── wp-content/
│ └── config/
├── database/
│ ├── mysql/
│ ├── wp-data/
│ └── config/
└── proxy/
├── data/
└── letsencrypt/
wordpress/
: Contains WordPress configuration and contentdatabase/
: Contains MySQL data and phpMyAdmin configurationproxy/
: Contains Nginx Proxy Manager data and certificates
-
Viewing Database
- Log in to phpMyAdmin at http://127.0.0.1:8080
- Navigate to your database (default: wordpress)
- Browse tables, run queries, and manage data
-
Common Operations
- View table structure and data
- Export/Import databases
- Run SQL queries
- Manage users and permissions
-
Backup Database
docker-compose exec db mysqldump -u root -p wordpress > backup.sql
-
Stop All Services
docker-compose down
-
View Logs
docker-compose logs -f [service_name]
Replace [service_name] with: wp, db, proxy, or pma
You can run multiple WordPress sites using this setup, sharing the main MySQL server but with separate databases. Here's how to set up additional sites:
-
Create New Site Directory Structure
# Create required directories mkdir -p site2/{config,wp-app/wp-content} # Copy configuration files cp wordpress/config/wp_php.ini site2/config/
-
Set Up Configuration Files
-
Create
.env
from template:cd site2 cp .env.sample .env
-
Configure in
.env
:- Different PORT (e.g., 8001)
- Different DB_NAME (e.g., wordpress_site2)
- Same DB_ROOT_PASSWORD as main site
-
Create wp-config.php with:
- Unique table prefix (e.g., 'wp_site2_')
- Different authentication keys and salts
-
-
Create Database and Start Site
# Create new database docker-compose exec db mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS wordpress_site2;" # Navigate to site directory cd site2 # Start WordPress docker-compose up -d
Your new site will be available at http://127.0.0.1:8001 (or your configured IP:PORT)
Each site has its own:
- Docker Compose file (using shared MySQL)
- WordPress container
- Environment configuration
- wp-content directory
- Database (on shared MySQL server)
Benefits of this approach:
- Simplified database management
- Shared MySQL resources
- Independent WordPress instances
- Separate content directories
- Easy database backups through phpMyAdmin
You can still use the main installation's Nginx Proxy Manager to:
- Set up different domains for each site
- Manage SSL certificates
- Configure reverse proxies for all sites
- The wp-content directory is persistent and stored locally
- Database data is stored in ./database/mysql
- For production, ensure you change all default passwords in .env
- Keep your WordPress core, themes, and plugins updated using WP-CLI
The Nginx Proxy Manager allows you to easily set up reverse proxies for your WordPress site. This is particularly useful when:
- You want to access your site using a domain name instead of IP:PORT
- You need to set up SSL/TLS certificates
- You're running multiple sites on different ports
-
Access Nginx Proxy Manager
- Go to http://127.0.0.1:81
- Log in with default credentials (if first time)
- Change default password when prompted
-
Add a New Proxy Host
- Click "Add Proxy Host"
- Fill in the following:
- Domain Names: Your domain (e.g., yourdomain.local)
- Scheme: http
- Forward Hostname/IP: wp
- Forward Port: 80
- Configure any additional settings as needed
-
SSL/TLS Configuration (Optional)
- In the SSL tab of your proxy host:
- Select "Request a new SSL Certificate"
- Or "Use a custom certificate" if you have one
- Enable Force SSL if desired
- In the SSL tab of your proxy host:
-
Advanced Configuration
- Custom locations
- Websockets support
- Access lists
- Custom headers
- The container name 'wp' is used as the Forward Hostname because Docker's internal DNS will resolve it
- Make sure your domain points to your server's IP if using a real domain
- For local development, add your domain to your hosts file