Log inSign up

WordPress on a hand-built LEMP stack

Install Nginx, PHP-FPM with the WordPress extensions and MariaDB from your distribution, create a database and user, then let WP-CLI download, configure and install WordPress in one pass. Finish with a Certbot certificate and a firewall that only opens SSH, HTTP and HTTPS. If you would rather skip the build, the WordPress app image gives you the same result at deploy time.

Topic: Websites, CMS and shops · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

Should you build the stack or use the WordPress image?

Pick the WordPress app image when you want a working site in minutes, and build by hand when you want to know and control every file. The image is Ubuntu 24.04 with the web stack already in place, so you only finish the setup wizard and add a certificate. A manual build takes about twenty minutes and leaves you with a server you can rebuild from notes, which pays off later when you tune caching, move to a larger plan or debug an outage.

This guide assumes a fresh instance, a sudo user called deploy (see your first SSH session), and a domain such as example.net whose A and AAAA records point at the server, as described in DNS records. A 1 GB plan runs a small blog; 2 GB or more gives MariaDB and PHP room to breathe once plugins pile up.

How do you install Nginx, PHP-FPM and MariaDB?

Use the packages your distribution ships. They receive security fixes through normal updates and match the PHP versions WordPress supports today.

Ubuntu 24.04, Debian 12 and 13

sudo apt update
sudo apt install -y nginx mariadb-server php-fpm php-mysql php-curl php-gd \
  php-intl php-mbstring php-xml php-zip php-imagick php-bcmath unzip
php -v
systemctl status nginx mariadb --no-pager

Ubuntu 24.04 installs PHP 8.3, Debian 12 installs 8.2 and Debian 13 installs 8.4. The FPM socket name follows the version, for example /run/php/php8.3-fpm.sock. Check yours with ls /run/php/.

Rocky Linux 9 and AlmaLinux 9

sudo dnf module reset -y php
sudo dnf module enable -y php:8.2
sudo dnf install -y nginx mariadb-server php-fpm php-mysqlnd php-gd php-intl \
  php-mbstring php-xml php-pecl-zip php-bcmath php-opcache unzip
sudo systemctl enable --now nginx mariadb php-fpm

On the RHEL family PHP-FPM runs as the apache user by default. Open /etc/php-fpm.d/www.conf and set user = nginx and group = nginx, then restart php-fpm. The socket lives at /run/php-fpm/www.sock.

How do you prepare the database?

Secure MariaDB first, then create one database and one user that only WordPress uses.

sudo mariadb-secure-installation
sudo mariadb

Inside the MariaDB prompt:

CREATE DATABASE wpsite CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'use-a-long-random-password';
GRANT ALL PRIVILEGES ON wpsite.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Keeping the user bound to localhost means nothing outside the server can sign in with it, even if port 3306 were opened by mistake. Generate the password with openssl rand -base64 24 and store it in your password manager.

How do you install WordPress with WP-CLI?

WP-CLI is a single PHP archive that downloads, configures and installs WordPress from the shell, and it stays useful for every later update.

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --version

Create the site directory, give it to the web server user and run every WordPress command as that user so file ownership stays consistent. On Ubuntu and Debian that user is www-data; on Rocky and Alma replace it with nginx.

sudo mkdir -p /var/www/example.net
sudo chown www-data:www-data /var/www/example.net
cd /var/www/example.net
sudo -u www-data wp core download
sudo -u www-data wp config create --dbname=wpsite --dbuser=wpuser \
  --dbpass='use-a-long-random-password' --dbhost=localhost
sudo -u www-data wp core install --url=https://example.net \
  --title="Example Site" --admin_user=siteadmin \
  --admin_email=admin@example.net --prompt=admin_password

The --prompt flag asks for the admin password interactively, so it never lands in your shell history. Avoid admin as the username; it is the first name bots try.

What does the Nginx server block look like?

One server block serves the site, hands PHP to FPM and blocks direct access to files that should stay private. Save it as /etc/nginx/sites-available/example.net on Ubuntu and Debian, or /etc/nginx/conf.d/example.net.conf on Rocky and Alma.

server {
    listen 80;
    listen [::]:80;
    server_name example.net www.example.net;
    root /var/www/example.net;
    index index.php;
    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|git) { deny all; }
    location = /xmlrpc.php { deny all; }
    location ~* \.(css|js|png|jpg|jpeg|gif|svg|webp|woff2)$ {
        expires 30d;
        access_log off;
    }
}

On Ubuntu and Debian enable it with sudo ln -s /etc/nginx/sites-available/example.net /etc/nginx/sites-enabled/ and remove the default site link. On Rocky and Alma replace the PHP block with include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php-fpm/www.sock;. Then test and reload:

sudo nginx -t && sudo systemctl reload nginx

Raise upload_max_filesize and post_max_size in the FPM php.ini to match the 64 MB body size if you upload large media.

How do you open the firewall and add HTTPS?

Allow only SSH, HTTP and HTTPS, then request a certificate with Certbot, which edits the Nginx block for you and sets up renewal. The broader rule set is in firewall rules.

# Ubuntu and Debian
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo apt install -y certbot python3-certbot-nginx

# Rocky and Alma
sudo firewall-cmd --permanent --add-service={http,https}
sudo firewall-cmd --reload
sudo dnf install -y epel-release
sudo dnf install -y certbot python3-certbot-nginx

sudo certbot --nginx -d example.net -d www.example.net
sudo certbot renew --dry-run

On Rocky and Alma with SELinux enforcing, let PHP write uploads with sudo chcon -R -t httpd_sys_rw_content_t /var/www/example.net/wp-content and allow outbound requests for updates with sudo setsebool -P httpd_can_network_connect 1.

How do you confirm that everything works?

Check from the server and from your own computer. A 200 or 301 response with the right headers tells you Nginx, PHP and the database are wired together.

curl -I https://example.net
sudo -u www-data wp option get siteurl --path=/var/www/example.net
sudo -u www-data wp db check --path=/var/www/example.net
ss -tlnp | grep -E ':80|:443|:3306'

Port 3306 should appear only on 127.0.0.1. Then sign in at https://example.net/wp-admin/ and open Tools, Site Health, which lists missing PHP modules and loopback problems in plain language.

How do you keep the site updated?

Update the operating system and WordPress on a schedule rather than when something breaks. WP-CLI updates core, plugins and themes in three short commands:

cd /var/www/example.net
sudo -u www-data wp core update
sudo -u www-data wp plugin update --all
sudo -u www-data wp theme update --all
sudo -u www-data wp core update-db

Take a backup before each round; the WordPress backup guide covers files, database and off-server copies. For speed, continue with Redis and page caching, and if something goes wrong after an update, the troubleshooting guide walks through the usual errors.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-2a single blog with a few plugins1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months
A2-4busier sites or several WordPress installs2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months
F2-4NVMe speed for heavier themes2 vCPU, 4 GB RAM, 128 GB NVMe$14.40/mo$43.20 for 3 months

Questions about WordPress on Nginx, PHP-FPM, MariaDB

Which PHP version should WordPress run on?

The version your distribution ships is fine: 8.3 on Ubuntu 24.04, 8.2 on Debian 12 and Rocky or Alma with the php:8.2 module, 8.4 on Debian 13. Check plugin compatibility before moving to a newer branch.

Can I host several WordPress sites on one server?

Yes. Give each site its own directory, database, database user and Nginx server block. For strict separation, add a PHP-FPM pool per site running as its own system user.

Why does WordPress ask for FTP details when I install a plugin?

It cannot write to its own directory. Make sure the files belong to the PHP-FPM user (www-data or nginx) and that FPM really runs as that user.

Is the WordPress image different from this manual setup?

It reaches the same goal on Ubuntu 24.04 with the stack already installed, so you skip the package and config steps. You still add your domain, HTTPS and your own update routine.

Do I need to open port 3306?

No. WordPress talks to MariaDB over localhost. Keep the database port closed to the internet and use an SSH tunnel if you want a desktop client.