Support Online
Skip to main content

WordPress Installation and Optimization with Docker Compose

Keyword: Docker Compose WordPress installation

📘 What Will You Learn in This Guide?

In this guide, you will install WordPress in a modern, secure and scalable way with Docker Compose.
After installation, you will learn How ​​to improve WordPress performance and security on Ubuntu.
SSL certificate, automatic renewal, theme-plugin optimization and cache strategies are discussed.


🧠 Technical Summary (Analysis)

This guide solves two main problems:

  • WordPress installation is complex and error-prone
  • Neglecting performance and security after installation

MySQL, WordPress (PHP-FPM), Nginx and Certbot container architecture is used as a solution.
Then, theme, plugin, cache and security optimizations are applied on Ubuntu.


🔧 Prerequisites

  • Ubuntu 22.04 or above server
  • Docker and Docker Compose must be installed
  • Domain name and DNS A records must be configured
  • Non-root, sudo authorized user

🔹 CHAPTER 1: Installing WordPress with Docker Compose

1️⃣ Nginx Web Server Configuration

  1. Create the project directory:
mkdir wordpress && cd wordpress
  1. Nginx configuration directory:

mkdir nginx-conf

  1. Open the configuration file:

nano nginx-conf/nginx.conf

  1. Add the HTTP configuration:

server {
listen 80;
server_name siteadresiniz.com www.siteadresiniz.com;

root /var/www/html;
index index.php index.html;

location ~ /.well-known/acme-challenge {
allow all;
root /var/www/html;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
fastcgi_pass wordpress:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
  • This structure redirects PHP requests to the WordPress container.

2️⃣ Environment Variables (.env)


nano .env

MYSQL_ROOT_PASSWORD=guclu_root_sifre
MYSQL_USER=wp_user
MYSQL_PASSWORD=wp_db_sifre

Sensitive information is not written directly to the compose file.


3️⃣ Docker Compose Services


nano docker-compose.yml


version: '3'

services:
db:
image: mysql:8.0
env_file: .env
environment:
MYSQL_DATABASE: wordpress
volumes:
- dbdata:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password

wordpress:
image: wordpress:php8.2-fpm
depends_on:
- db
env_file: .env
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: ${MYSQL_USER}
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress:/var/www/html

webserver:
image: nginx:alpine
ports:
- "80:80"
volumes:
- wordpress:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt

certbot:
image: certbot/certbot
volumes:
- wordpress:/var/www/html
- certbot-etc:/etc/letsencrypt
command: certonly --webroot --webroot-path=/var/www/html \
--email admin@siteadresiniz.com --agree-tos --staging \
-d siteadresiniz.com -d www.siteadresiniz.com

volumes:
dbdata:
wordpress:
certbot-etc:

4️⃣ Obtaining an SSL Certificate


docker-compose up -d
  • Log control:

docker-compose logs certbot
  • If successful, --staging is removed and the real certificate is obtained.

5️⃣ HTTPS Configuration

  • Added HTTP → HTTPS redirect and security headers.
  • Nginx 443 port is opened and the service is restarted.

6️⃣ WordPress Web Installation

  1. From the browser:

https://siteadresiniz.com

Site name, administrator and password are determined.


7️⃣ SSL Auto-Renewal (Cron)


nano ssl_renew.sh

#!/bin/bash
docker-compose run certbot renew && docker-compose kill -s SIGHUP webserver


chmod +x ssl_renew.sh
sudo crontab -e

0 12 * * * /home/user/wordpress/ssl_renew.sh

🔹 CHAPTER 2: WordPress Optimization on Ubuntu

8️⃣ Infrastructure and Location Strategy

  • Server location directly affects latency.
  • TR location is ideal for sites targeting Türkiye.

Current PHP 8.x versions provide serious speed improvements.


9️⃣ Theme and Plugin Discipline

  1. Light themes should be preferred.
  2. Unused theme modules should be closed.

Using few but high-quality plugins increases performance.


🔟 Security and Tweaks

  1. /wp-admin address must be changed

  2. Tools > Site Health should be checked regularly

  3. Brute-force attacks should be prevented


1️⃣1️⃣ Caching

Caching is a must.

Recommended plugins:

  1. LiteSpeed Cache

  2. WP Super Cache

  3. W3 Total Cache

❓ Frequently Asked Questions (FAQ)

1. Does Docker Compose improve performance? Yes, it provides isolation and build standards.

2. Will the data be deleted? No, it is permanent with Docker volume.

3. Nginx or Apache? Nginx is more efficient in high traffic.

4. Does Cache affect SEO? Yes, site speed affects ranking.

🏁 Result

With this guide, you installed WordPress in a modern, secure and high-performance way. The infrastructure was simplified with Docker Compose, and speed peaked with Ubuntu optimizations.

🚀 You can implement this structure in minutes on the GenixNode infrastructure.