In this guide, we’ll walk you through the process of hosting WordPress locally using Docker Compose and setting up Cloudflare Zero Trust Tunnel as a reverse proxy. This setup allows you to run WordPress on your local machine while securely exposing it to the internet via Cloudflare’s Zero Trust Tunnel.
Prerequisites
- Docker and Docker Compose installed on your local machine.
- A Cloudflare account with access to Zero Trust Tunnel.
Step 1: Set Up WordPress with Docker Compose
- Create a Docker Compose File: Create a new directory for your WordPress project and navigate into it. Then, create a file named
docker-compose.yml
with the following content:
version: '3.1'
services:
wordpress:
image: wordpress:latest
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress_data:/var/www/html
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data:
- Start Docker Compose: Run the following command to start the WordPress and MySQL containers:
docker-compose up -d
- Access WordPress: Open your web browser and navigate to
http://localhost:8000
. You should see the WordPress installation page.
Step 2: Set Up Cloudflare Zero Trust Tunnel
- Install Cloudflare Tunnel: Download and install the Cloudflare Tunnel CLI (
cloudflared
) from the Cloudflare Tunnel documentation. - Authenticate Cloudflare Tunnel: Run the following command to authenticate
cloudflared
with your Cloudflare account:
cloudflared tunnel login
Follow the instructions to log in to your Cloudflare account and authorize the tunnel.
- Create a New Tunnel: Create a new tunnel with a unique name:
cloudflared tunnel create my-wordpress-tunnel
- Configure the Tunnel: Create a configuration file for your tunnel named
config.yml
with the following content:
tunnel: <TUNNEL_ID>
credentials-file: /path/to/.cloudflared/<TUNNEL_ID>.json
ingress:
- hostname: wordpress.example.com
service: http://localhost:8000
- service: http_status:404
Replace <TUNNEL_ID>
with the ID of your tunnel, and wordpress.example.com
with your desired hostname.
- Start the Tunnel: Run the following command to start the tunnel:
cloudflared tunnel run my-wordpress-tunnel
Step 3: Configure DNS and Access
- Add a DNS Record: In your Cloudflare dashboard, navigate to the DNS settings for your domain. Add a CNAME record pointing
wordpress.example.com
(or your chosen hostname) to<TUNNEL_ID>.cfargotunnel.com
. - Set Up Access Policies: In the Cloudflare dashboard, navigate to the Zero Trust section and create an access policy for your hostname to define who can access your WordPress site.
Conclusion
You have successfully set up WordPress locally with Docker Compose and exposed it to the internet using Cloudflare Zero Trust Tunnel as a reverse proxy. This setup provides a secure and scalable way to host WordPress for development or testing purposes.
Leave a Reply