Updated: 28 September 2026 · Applies to: Ubuntu 24.04 LTS

Ubuntu 18.04 is no longer supported, so this guide now uses Ubuntu 24.04 LTS.

A complete WordPress setup on Ubuntu 24.04 with Nginx, MariaDB and PHP-FPM, secured with HTTPS.

Before you start

  • A VPS or dedicated server with a fresh Ubuntu 24.04 / Debian 12 or AlmaLinux 9 / Rocky Linux 9 installation, and root or sudo access.
  • A domain or subdomain pointing to the server (an A record), if you want HTTPS.
  • The system updated: apt update && apt upgrade or dnf upgrade.

Install Nginx, MariaDB and PHP-FPM

Ubuntu 24.04 / Debian 12:

apt install nginx mariadb-server php-fpm php-mysql php-xml php-mbstring php-curl php-zip php-gd php-intl
systemctl enable --now nginx mariadb php8.3-fpm   # php8.2-fpm on Debian 12

AlmaLinux 9 / Rocky Linux 9:

dnf module reset php && dnf module enable php:8.3
dnf install nginx mariadb-server php-fpm php-mysqlnd php-xml php-mbstring php-gd php-intl php-opcache php-pecl-zip
systemctl enable --now nginx mariadb php-fpm

On AlmaLinux 9 / Rocky Linux 9, edit /etc/php-fpm.d/www.conf and set user = nginx and group = nginx, then restart php-fpm. Secure MariaDB with mariadb-secure-installation.

Create a database

mariadb -u root -p
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'Strong-Password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Download WordPress

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

Then open your domain in a browser and follow the installer: enter the database name, user and password you created, and create the admin account (do not call it "admin").

Create the Nginx server block

Create /etc/nginx/sites-available/example.com and link it into sites-enabled (Ubuntu/Debian), or create /etc/nginx/conf.d/example.com.conf (AlmaLinux/Rocky):

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

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;   # /run/php-fpm/www.sock on AlmaLinux/Rocky
    }
}

Check and reload: nginx -t && systemctl reload nginx.

Performance and security

  • Raise upload_max_filesize and post_max_size in /etc/php/8.3/fpm/php.ini if you upload large media, then restart PHP-FPM.
  • Deny access to sensitive files: location ~ /\.(?!well-known) { deny all; }.
  • Install a caching plugin, and keep WordPress, themes and plugins updated.

Open the firewall

ufw allow 80,443/tcp                                   # Ubuntu / Debian with UFW
firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload   # AlmaLinux / Rocky

Add a free SSL certificate

apt install certbot python3-certbot-nginx                     # Ubuntu / Debian
dnf install epel-release && dnf install certbot python3-certbot-nginx   # AlmaLinux / Rocky
certbot --nginx -d example.com -d www.example.com

Certbot installs a timer that renews the certificate automatically; test it with certbot renew --dry-run.

Related services

Web hosting

shared hosting on Virtualmin with NVMe storage, free SSL and email.

Managed cPanel VPS

cPanel included; we handle updates, security and monitoring.

Hire an expert

engineers per 15 minutes, per hour or per month, with no contract.

Was this answer helpful?

Still stuck? Open a ticket