Hong Kong Server · July 17, 2025

Deploying WordPress with Docker Compose on a Hong Kong Server

WordPress, a powerful open-source platform built on PHP and MySQL, powers over 43% of websites worldwide. This guide walks you through deploying WordPress using Docker Compose on a Hong Kong server, integrating Nginx and Let’s Encrypt SSL for a secure and efficient website.

## Prerequisites: Setting Up Docker on a Hong Kong VPS

To run WordPress and MariaDB containers, start by installing Docker on your Hong Kong VPS. Follow these steps:

1. **Update System Packages**
“`bash
sudo apt update
“`

2. **Install Docker**
If Docker isn’t already installed, run:
“`bash
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
“`
If the official source is unreachable, use a domestic mirror:
“`bash
curl -fsSL https://mirrors.cloud.tencent.com/docker-ce/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.cloud.tencent.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
“`
Install and start Docker:
“`bash
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
“`

3. **Verify Docker Compose Installation**
Confirm Docker Compose is installed:
“`bash
docker-compose –version
“`

## Creating the Docker Compose Configuration

Set up a project directory on your Hong Kong  server, for example, `~/wordpress`:
“`bash
mkdir ~/wordpress
cd ~/wordpress
“`

Create and edit the `docker-compose.yaml` file:
“`yaml
version: ‘3’

services:
wordpress:
image: wordpress:latest
ports:
– “8080:80”
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress_user
WORDPRESS_DB_PASSWORD: yourpassword
WORDPRESS_DB_NAME: wordpress_db
volumes:
– ./wp_data:/var/www/html

db:
image: mariadb:latest
environment:
MYSQL_DATABASE: wordpress_db
MYSQL_USER: wordpress_user
MYSQL_PASSWORD: yourpassword
MYSQL_ROOT_PASSWORD: yourpassword
volumes:
– ./mariadb:/var/lib/mysql
“`

## Launching the Containers

From the `~/wordpress` directory, start the containers:
“`bash
sudo docker-compose up -d
“`

## Configuring Nginx as a Reverse Proxy

To ensure secure access, configure Nginx as a reverse proxy on your Hong Kong server.

1. **Install Nginx**
“`bash
sudo apt install nginx
“`

2. **Check Nginx Status**
“`bash
sudo systemctl status nginx
“`

3. **Start and Enable Nginx**
“`bash
sudo systemctl start nginx
sudo systemctl enable nginx
“`

4. **Configure Nginx**
Create an Nginx configuration file:
“`bash
sudo nano /etc/nginx/sites-available/wordpress
“`
Add the following (replace `yourdomain.com` with your domain):
“`nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name yourdomain.com;

ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;

location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
“`
Enable the configuration:
“`bash
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
“`

## Securing with Let’s Encrypt SSL

Enhance security by configuring a Let’s Encrypt SSL certificate:

1. **Install Certbot**
“`bash
sudo apt-get update
sudo apt-get install certbot
“`

2. **Generate DNS-01 Challenge**
“`bash
sudo certbot certonly –manual –preferred-challenges dns -d yourdomain.com
“`
Certbot will provide a TXT record to add to your DNS settings.

3. **Add TXT Record**
Log in to your DNS provider’s console, add a TXT record with the name `_acme-challenge.yourdomain.com` and the value provided by Certbot.

4. **Verify DNS Record**
“`bash
nslookup -q=TXT _acme-challenge.yourdomain.com
“`
Ensure the returned value matches Certbot’s provided string.

5. **Complete Certificate Issuance**
Return to the Certbot terminal, press Enter to proceed, and obtain the certificate.

6. **Automate Renewal (Optional)**
If your DNS provider supports an API, automate certificate renewal. For example, with Cloudflare:
“`bash
sudo certbot certonly –dns-cloudflare –dns-cloudflare-credentials path/to/your/cloudflare.ini -d yourdomain.com
“`

## Accessing and Setting Up WordPress

Visit `https://yourdomain.com` in your browser to access the WordPress setup interface and complete the initial configuration.

## Conclusion

You’ve successfully deployed WordPress using Docker Compose on a Hong Kong VPS or Hong Kong  server, with Nginx and an SSL certificate ensuring a secure and high-performing website.