Understanding Docker and Containerising WordPress for Scalability (Part 1)


Denny Lim

Denny Lim

·June 24, 2025·
DockerWordpress

This guide is ideal for you if:

  • You currently have a single server setup running WordPress with PHP, MySQL, and Nginx
  • Your server struggles to handle traffic increases or fluctuations during peak hours or campaign periods
  • You want to containerise your WordPress application to achieve better scalability

This is a two-part tutorial:

  • Part 1: Installing WordPress on Ubuntu 24.04 with Nginx and MySQL 👈 You are here
  • Part 2: Understanding Docker and containerising WordPress

By the end of this tutorial series, you'll understand the key components powering your WordPress website and how containerisation can help achieve scalability.

Installing WordPress on Ubuntu 24.04 with Nginx and MySQL

This step-by-step guide will walk you through installing WordPress on Ubuntu 24.04, using Nginx as the web server and MySQL as the database. By the end, you’ll understand the essential components needed to run a WordPress site efficiently.

While this tutorial focuses on WordPress, the core concepts and fundamentals of containerizing applications remain consistent across other software types.

Prerequisites

  • Ubuntu 24.04 server
  • Root or sudo privileges
  • Domain name pointed to your server (recommended for production environments)

Step 1: Update System Packages

sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx

sudo apt install nginx -y

Start and enable Nginx:

sudo systemctl start nginx sudo systemctl enable nginx

Note: Verify Nginx is running by visiting your server's IP address in a web browser.

Step 3: Install MySQL

sudo apt install mysql-server -y

Secure your MySQL installation:

sudo mysql_secure_installation

Follow the prompts to set a root password and configure security options.

Step 4: Create WordPress Database

Log into MySQL:

sudo mysql -u root -p

Create database and user:

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'strongpassword'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost'; FLUSH PRIVILEGES; EXIT;

Important: Replace 'strongpassword' with a secure password of your choice.

Step 5: Install PHP and Required Extensions

sudo apt install php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip -y

Recommended: Verify PHP installation with php -v and check FPM status with sudo systemctl status php8.2-fpm (version may vary).

Step 6: Download WordPress

cd /tmp wget https://wordpress.org/latest.tar.gz tar -xzvf latest.tar.gz sudo mv wordpress /var/www/ sudo chown -R www-data:www-data /var/www/wordpress sudo chmod -R 755 /var/www/wordpress

Step 7: Configure Nginx for WordPress

Create a new Nginx configuration file:

sudo nano /etc/nginx/sites-available/wordpress

Add this configuration (replace example.com with your domain):

server { listen 80; server_name example.com www.example.com; root /var/www/wordpress; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }

Enable the site:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ sudo rm /etc/nginx/sites-enabled/default

Test and restart Nginx:

sudo nginx -t sudo systemctl restart nginx

Step 8: Configure WordPress

Set up the configuration file:

cd /var/www/wordpress sudo cp wp-config-sample.php wp-config.php sudo nano wp-config.php

Update database credentials:

define( 'DB_NAME', 'wordpress' ); define( 'DB_USER', 'wordpressuser' ); define( 'DB_PASSWORD', 'strongpassword' ); define( 'DB_HOST', 'localhost' );

Add security keys (generate fresh ones at https://api.wordpress.org/secret-key/1.1/salt/ ):

define( 'AUTH_KEY', 'put your unique phrase here' ); define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); define( 'NONCE_KEY', 'put your unique phrase here' ); define( 'AUTH_SALT', 'put your unique phrase here' ); define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); define( 'LOGGED_IN_SALT', 'put your unique phrase here' ); define( 'NONCE_SALT', 'put your unique phrase here' );

Step 9: Complete WordPress Installation

Access your site in a web browser:

http://your-server-ip-or-domain

Follow the WordPress installation wizard to complete setup.

Optional: Set Up SSL with Let's Encrypt

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Obtain and install SSL certificate:

sudo certbot --nginx -d example.com -d www.example.com

Configure automatic renewal:

sudo certbot renew --dry-run

Conclusion

You now have a fully functional WordPress installation on Ubuntu 24.04 with Nginx and MySQL. Before moving to production, consider implementing these additional security measures:

  • Configure Uncomplicated Firewall (UFW) to restrict unnecessary access
  • Set up a Web Application Firewall (Cloudflare or similar) for WordPress-specific protection
  • Implement regular automated backups of both files and database
  • Harden PHP security settings in php.ini
  • Set up server monitoring (e.g., Netdata, Prometheus) to track resource usage
  • Consider implementing fail2ban for additional security against brute force attacks

In Part 2, we'll explore how to containerise this setup using Docker to achieve better scalability and reliability.