Tutorials

Install WordPress with Nginx on Ubuntu 24.04

Set up a fast WordPress site on a fresh Ubuntu 24.04 VPS with Nginx, PHP-FPM, MariaDB and a free Let’s Encrypt certificate.

This tutorial installs WordPress on a clean Ubuntu 24.04 server using the LEMP stack: Nginx, MariaDB and PHP-FPM. It takes about 15 minutes on any RMDHost Linux VPS.

Before you start

  • A VPS running Ubuntu 24.04 with root or sudo access
  • A domain name with an A record pointing to your server’s IP address
  • SSH access – see Connecting to your server over SSH

1. Update the server

sudo apt update && sudo apt upgrade -y

2. Install Nginx, MariaDB and PHP

sudo apt install -y nginx mariadb-server php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl php-imagick unzip

Check the PHP-FPM version that was installed (Ubuntu 24.04 ships PHP 8.3):

php -v

3. Create the database

sudo mysql_secure_installation
sudo mysql

Inside the MariaDB prompt:

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'choose-a-strong-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

4. Download WordPress

cd /tmp && curl -O https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo mkdir -p /var/www/example.com
sudo cp -a wordpress/. /var/www/example.com/
sudo chown -R www-data:www-data /var/www/example.com

5. Configure Nginx

Create /etc/nginx/sites-available/example.com:

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php index.html;
    client_max_body_size 64M;

    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; }
}

Enable the site and reload Nginx:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

6. Add HTTPS with Let’s Encrypt

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

Certbot edits the Nginx configuration and sets up automatic renewal.

7. Finish the installer

Open https://example.com in your browser, choose a language and enter the database name, user and password you created in step 3. WordPress writes wp-config.php for you.

Next steps

  • Enable a firewall: sudo ufw allow 'Nginx Full' && sudo ufw allow OpenSSH && sudo ufw enable
  • Install a caching plugin and keep WordPress, themes and plugins updated
  • Schedule backups – see Automate backups to object storage with restic

Back to the blog

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Imagined it.
Now deploy it.

No setup fee on Linux & SSD VPS. Free migration help from our in-house engineers.

Get started
Small business owner smiling at a laptop after launching a website
yourproject.com
Server onlineDeployed in 38 seconds
Deploy a VPS in London