This project sets up a WordPress environment with Nginx and automatic SSL certificate management via Certbot using Docker. It is designed to make it easy to deploy a secure, production-ready WordPress site with SSL encryption.
- WordPress: The latest stable version of WordPress.
- Nginx: Acts as a reverse proxy with SSL support.
- Certbot: Automatically generates and renews SSL certificates.
- MySQL: Used as the database for WordPress.
- One-click deployment: A script to simplify setup and configuration.
- Docker and Docker Compose installed on your machine.
- To install Docker, follow the official Docker installation guide.
- To install Docker Compose, follow the official Docker Compose installation guide.
First, clone the repository to your local machine:
git clone https://github.com/Ushiao/docker-compose-wordpress-nginx-mysql.git
cd docker-compose-wordpress-nginx-mysqlTo configure the necessary environment variables (such as database credentials, domain name, and SSL email), you can use the .env file.
Create or modify the .env file in the project root directory:
# .env example
# WordPress Database Configuration
TAGWORD_DB_NAME=wordpress_tagword
TAGWORD_DB_USER=wordpress_user
TAGWORD_DB_PASSWORD=yourpassword
TAGWORD_DB_ROOT_PASSWORD=rootpassword
# Domain and SSL Configuration
DOMAIN_NAME=example.com
EMAIL=your-email@example.com- TAGWORD_DB_NAME: Name of the WordPress database.
- TAGWORD_DB_USER: Username for accessing the database.
- TAGWORD_DB_PASSWORD: Password for the WordPress database.
- TAGWORD_DB_ROOT_PASSWORD: Root password for the MySQL database.
- DOMAIN_NAME: Your website's domain name (e.g.,
sample.com). - EMAIL: Your email address for SSL certificate registration.
Alternatively, you can use the provided deploy.sh script to automatically configure the .env file, start the containers, and generate SSL certificates.
If you prefer an automated setup, simply run the one-click deployment script:
chmod +x deploy.sh
./deploy.shThis script will:
- Prompt you for the database and SSL details (if not already configured in
.env). - Automatically create the
.envfile. - Start the necessary Docker containers.
- Generate SSL certificates via Certbot for your specified domain.
Once the .env file is configured (or the script has created it for you), you can start the Docker containers using:
docker-compose up -dThis will start the following services:
- Nginx: A reverse proxy to forward requests to WordPress.
- WordPress: The WordPress application.
- MySQL: The MySQL database for WordPress.
- Certbot: To manage SSL certificates for secure HTTPS connections.
If you did not use the deploy.sh script, you can manually run Certbot to generate SSL certificates:
docker exec -it certbot certbot certonly --webroot --webroot-path=/var/www/certbot --email your-email@example.com --agree-tos --no-eff-email -d tagword.tech -d www.tagword.techOnce the containers are up and running, you can access your WordPress site via https://tagword.tech (or your configured domain name).
docker-wordpress-nginx-certbot/
│
├── docker-compose.yaml # Docker Compose configuration to define services
├── nginx.conf # Nginx configuration for reverse proxy and SSL
├── .env # Environment variables for sensitive configurations
├── deploy.sh # One-click deployment script
├── README.md # Project documentation
└── data/ # Persistent data for certificates, WordPress, and MySQL
├── certbot/
├── wordpress/
└── mysql/
- SSL Certificates: Certbot will automatically generate SSL certificates for your specified domain (via the
certbotservice). These certificates will be stored indata/certbot/. - Data Persistence: The WordPress and MySQL containers use Docker volumes to persist data across container restarts. Volumes are defined in the
docker-compose.yamlfile underwordpress_tagword_dataanddb_tagword_data.
- Missing Docker Compose: Ensure that Docker Compose is installed on your machine. You can verify by running
docker-compose --version. - Permissions: If you encounter permission errors with Docker, ensure your user is added to the
dockergroup. You can refer to the official Docker documentation for more details.
This project is licensed under the MIT License - see the LICENSE file for details.