Denny Lim
This guide is ideal for you if:
This is a two-part tutorial:
By the end of this tutorial series, you'll understand the key components powering your WordPress website and how containerisation can help achieve scalability.
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.
sudo apt update && sudo apt upgrade -y
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.
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.
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.
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).
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
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
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' );
Access your site in a web browser:
http://your-server-ip-or-domain
Follow the WordPress installation wizard to complete setup.
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
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:
php.ini
In Part 2, we'll explore how to containerise this setup using Docker to achieve better scalability and reliability.