Introduction

A LEMP stack (Linux, Nginx, MariaDB/MySQL, PHP) is one of the fastest, most resource-efficient ways to host WordPress. Compared to Apache-based setups, Nginx uses less memory under load and serves concurrent visitors with ease, which makes LEMP the go-to choice for VPS hosting.

In this guide you will install WordPress on Ubuntu 24.04 with Nginx, MariaDB, and PHP 8.3 from the official Ubuntu repositories. By the end you will have a working WordPress site behind Nginx with a proper server block, database, and optional free SSL via Let's Encrypt. This guide is written for anyone with basic Linux comfort: you can paste commands and follow instructions, but you do not need to be a sysadmin.

Prerequisites

  • Ubuntu 24.04 LTS (22.04 works too; package names may vary slightly) with at least 1 GB RAM.
  • Root or sudo access.
  • A domain name pointed at your server's IP address (for production use; a bare IP works for testing).
  • Ports 80 and 443 open in your firewall (UFW): sudo ufw allow 'Nginx Full'.

Step 1: Update the system

Always start with a fresh package index and updated system packages so you install current, patched versions.

sudo apt update && sudo apt upgrade -y

The first half refreshes the list of available packages; the second applies updates. On a fresh VPS this can take a few minutes.

Step 2: Install Nginx

Nginx is the web server in LEMP. It listens on port 80/443 and serves PHP pages through PHP-FPM.

sudo apt install nginx -y
sudo systemctl enable --now nginx

enable --now starts Nginx immediately and makes it start on every boot. Verify it is running:

sudo systemctl status nginx
curl -I http://localhost

You should see HTTP/1.1 200 OK and the default Nginx welcome page if you visit your server's IP in a browser.

Step 3: Install MariaDB

MariaDB is a community fork of MySQL, ships in Ubuntu's default repositories, and is fully compatible with WordPress.

sudo apt install mariadb-server -y
sudo systemctl enable --now mariadb

This installs the database server and starts it. Now harden the default installation:

sudo mysql_secure_installation

Answer the prompts: set a root password (or leave the unix_socket auth default), remove anonymous users, disallow remote root login, remove the test database, and reload privilege tables. Saying "yes" to all the prompts is safe on a fresh server.

Step 4: Create the WordPress database and user

WordPress needs its own database and a dedicated user. Never run WordPress as the database root user.

sudo mysql -u root -p

Inside the MariaDB prompt, run these statements (replace the password with a strong one):

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

utf8mb4 is WordPress's expected character set; it handles emoji and full Unicode. The GRANT gives wpuser full control over only the wordpress database, nothing else.

Step 5: Install PHP 8.3 and required extensions

Ubuntu 24.04 ships PHP 8.3, which is officially supported by current WordPress releases. Install PHP-FPM (the FastCGI process manager Nginx talks to) plus every extension WordPress recommends.

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

Confirm the PHP-FPM service is running:

sudo systemctl enable --now php8.3-fpm
sudo systemctl status php8.3-fpm

Check the socket Nginx will connect to:

ls /run/php/php8.3-fpm.sock

If that file exists, PHP-FPM is ready. The extensions cover image processing (gd, imagick), HTTP requests (curl), multibyte strings (mbstring), and XML/SOAP APIs many plugins rely on.

Step 6: Download and set up WordPress

Fetch the latest WordPress release from wordpress.org and place it in Nginx's default web root.

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
sudo mkdir -p /var/www/wordpress
sudo cp -a /tmp/wordpress/. /var/www/wordpress/

Set ownership so Nginx (the www-data user) can read and write files, which WordPress needs for uploads and updates:

sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress -type f -exec chmod 644 {} \;

Directories get 755 and files 644: readable by the web server, writable only by the owner. Clean up the download:

rm -rf /tmp/wordpress /tmp/latest.tar.gz

Step 7: Configure the Nginx server block

Create a dedicated server block for your domain (replace example.com with your domain, or use your server IP for testing):

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

Paste this configuration:

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/php8.3-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; }

    access_log /var/log/nginx/wordpress-access.log;
    error_log /var/log/nginx/wordpress-error.log;
}

Key lines explained: try_files makes WordPress permalinks work by routing unknown URLs to index.php; fastcgi_pass hands PHP files to the PHP 8.3 socket we verified earlier; the /\.ht block denies access to hidden files.

Enable the site, remove the default, and test the config:

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

nginx -t must print syntax is ok and test is successful before you reload.

Step 8: Finish installation through the WordPress wizard

Open http://example.com in your browser (or your server's IP). The famous 5-minute WordPress installer appears:

  1. Choose your language and click Continue.
  2. Enter the database details: database name wordpress, username wpuser, the password you set, host localhost, table prefix wp_ (change it for a small security gain).
  3. Click Submit, then Run the installation.
  4. Set your site title, admin username, a strong password, and your email.
  5. Click Install WordPress and log in at http://example.com/wp-admin.

Step 9: Add free SSL with Let's Encrypt (recommended)

HTTPS is expected by browsers, search engines, and visitors. Certbot automates the whole thing with Nginx.

sudo apt install python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com

Follow the prompts (enter your email, agree to the terms, choose to redirect HTTP to HTTPS). Certbot edits your Nginx config, installs the certificate, and sets up automatic renewal. Verify renewal works:

sudo certbot renew --dry-run

A successful dry run means your certificate will renew automatically before it expires.

Verify it worked

  • curl -I https://example.com returns HTTP/2 200.
  • The homepage loads with your site title and the default theme.
  • https://example.com/wp-admin lets you log in and create a test post.
  • Permalinks: go to Settings > Permalinks, choose "Post name", save, and open a post — it must load, not 404.
  • sudo systemctl is-active nginx php8.3-fpm mariadb prints active three times.

Common issues & fixes

1. 502 Bad Gateway

The PHP-FPM socket path in your Nginx config does not match the installed PHP version. Check the socket actually exists with ls /run/php/ and update the fastcgi_pass line accordingly (e.g. php8.2-fpm.sock on Ubuntu 22.04), then sudo systemctl reload nginx.

2. "Error establishing a database connection"

Wrong DB credentials in the installer, or MariaDB is not running. Re-check the username/password with sudo mysql -u root -p and confirm sudo systemctl status mariadb shows active.

3. Permalinks return 404

Your server block is missing the try_files $uri $uri/ /index.php?$args; line, or you edited the wrong file. Add it inside location /, run sudo nginx -t, and reload Nginx.

4. File uploads fail or updates ask for FTP credentials

Ownership is wrong. Re-run sudo chown -R www-data:www-data /var/www/wordpress so the web server user owns the files.

5. Mixed content warnings after enabling SSL

WordPress still thinks its URL is http. In wp-admin go to Settings > General and change both URLs to https://, or add these lines to wp-config.php:

define('WP_HOME', 'https://example.com');
define('WP_SITEURL', 'https://example.com');

Conclusion

You now have WordPress running on a clean LEMP stack on Ubuntu 24.04: Nginx serving pages, PHP 8.3 handling code, MariaDB storing data, and free Let's Encrypt SSL protecting traffic. This setup comfortably handles a small-to-medium blog on a 1-2 GB VPS and is easy to scale with caching plugins or a CDN later.

Need help hardening, migrating, or tuning a WordPress server? XpertBees sets up and manages production servers for businesses every day — get in touch and we will take care of it.