If you’re looking to set up a WordPress server for your website, this guide will walk you through the entire process, from domain configuration to security best practices. The steps outlined here are designed for everyone, whether you’re a beginner or a seasoned tech enthusiast.
Prerequisites
Before diving into the setup process, ensure you have the following ready
- A Debian Linux server with an attached data disk. Debian is preferred due to its minimal packages and lightweight nature.
- Docker, Nginx, and Certbot installed on the server.
- A registered domain name (e.g.,
karthiks.com
).
Step 1: Configure DNS Records
Add the following DNS records to point your domain to your server
A Record
Type: A
Name: @
Value: Public IP of your server (e.g., 123.456.789.101)
TTL: Default (1 Hour)
CNAME Record
Type: CNAME
Name: www
Value: Your root domain name (e.g., karthiks.com)
TTL: Default (1 Hour)
Step 2: Create a Docker Compose File
Create a compose.yml
file with the following contents
version: '3.1'
services:
wordpress:
image: wordpress:6.7.0
restart: unless-stopped
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: <your-database-username>
WORDPRESS_DB_PASSWORD: <your-database-passowrd>
WORDPRESS_DB_NAME: <your-database-name>
volumes:
- ./wordpress:/var/www/html
db:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_DATABASE: <your-database-name>
MYSQL_USER: <your-database-username>
MYSQL_PASSWORD: <your-database-passowrd>
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- ./db:/var/lib/mysql
Step 3: Create Folders for Persistent Storage
Run the following command to create folders for storing WordPress and database data
mkdir wordpress db
Step 4: Configure Nginx
Create an Nginx configuration file with the following content
# Redirect non-www to www
server {
listen 80;
server_name karthiks.com;
return 301 http://www.karthiks.com$request_uri;
}
server {
server_name www.karthiks.com;
location / {
proxy_pass http://127.0.0.1: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;
}
}
Make sure to change karthiks.com and www.karthiks.com to your domain name.
Link this configuration file to Nginx
sudo ln -s /etc/nginx/sites-available/your-config /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Step 5: Enable SSL with Certbot
Run the following command to configure SSL
sudo certbot --nginx -d karthiks.com -d www.karthiks.com
Make sure to change karthiks.com and www.karthiks.com to your domain name.
Step 6: Finalize WordPress Setup
Access your domain in a browser (e.g., http://www.karthiks.com
) and complete the WordPress setup by entering the desired username, password, and site details.
Security Best Practices
Protecting wp-login.php
To secure the WordPress login page, whitelist only authorized IP addresses.
Open the .htaccess
file located in your WordPress directory and Add the following lines
# Block access to wp-login.php.
<Files wp-login.php>
order deny,allow
allow from 203.0.113.15
deny from all
</Files>
Restart the Docker container using the following command
docker compose restart
Your WordPress Server Is Ready!
You’ve successfully set up a secure and reliable WordPress server with Debian, Docker, and Nginx. Enjoy managing your site with peace of mind.
For any issues or additional customization, feel free to tweak the configurations as needed.