Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Self-hosting

Install WordPress on a VPS with Nginx and MariaDB

Install WordPress on an Ubuntu 24.04 VPS by hand: Nginx, PHP-FPM, MariaDB, a Let's Encrypt certificate and WP-CLI, plus the checks to run before launch.

CloudSat teamNovember 18, 20267 min read
Abstract illustration of building blocks stacking into a website frame on top of a glowing server
On this pageWhat you need first

A one-click image gets WordPress running in under 5 minutes. Installing it by hand takes about half an hour, and in exchange you know where every file, password and setting lives, which is what you need the first time something breaks. This guide builds a WordPress 7.1 site on Ubuntu 24.04 LTS with Nginx, PHP-FPM and MariaDB, adds a free certificate, and leaves WP-CLI on the server for everything that comes after.

What you need first

  • A server with at least 1 GB of RAM. The database and PHP are more comfortable with 2 GB, and a 2 GB Cloud VPS costs $5.98/mo.
  • Ubuntu 24.04 LTS. It ships PHP 8.3, MariaDB 10.11 and Nginx 1.24, all supported by WordPress 7.1.
  • A domain whose A record (and AAAA if you use IPv6) already points at the server. The certificate step fails until it resolves.
  • SSH access as a user with sudo. See Connect to a Linux server over SSH if you have not logged in yet.

If you would rather skip the manual work, CloudSat's WordPress one-click app deploys the same kind of stack for you.

Open the web ports in the server's firewall, and in your cloud firewall if you use one (Create and apply cloud firewalls):

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable

Install Nginx, PHP and MariaDB

sudo apt update && sudo apt upgrade -y
sudo apt install -y nginx mariadb-server \
  php8.3-fpm php8.3-cli php8.3-mysql php8.3-curl php8.3-gd php8.3-intl \
  php8.3-mbstring php8.3-xml php8.3-zip php-imagick
systemctl is-active nginx mariadb php8.3-fpm

The last command should print active three times. php8.3-cli matters even though Nginx talks to PHP-FPM: WP-CLI runs on the command-line PHP.

Raise PHP's upload and memory limits for WordPress in a file of your own, so package upgrades never overwrite it:

; /etc/php/8.3/fpm/conf.d/90-wordpress.ini
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
sudo systemctl restart php8.3-fpm

Create the database and its user

Run sudo mariadb-secure-installation and answer yes to removing anonymous users, the test database and remote root login. On Ubuntu, root logs in through the Unix socket, so keep that and do not set a root password over the network.

Then create one database and one user that can only touch it:

DB_PASS="$(openssl rand -base64 24)"
echo "$DB_PASS"    # save it in your password manager
sudo mariadb <<SQL
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp'@'localhost' IDENTIFIED BY '${DB_PASS}';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp'@'localhost';
SQL

The user exists only for localhost, so the database never has to listen on a public interface. MariaDB on Ubuntu listens on 127.0.0.1 by default; leave it that way.

Download WordPress with WP-CLI

WP-CLI is a single PHP archive. Install it once, system-wide:

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

Create the site directory and let the web server's user own it, then fetch WordPress and write wp-config.php with fresh security keys:

sudo install -d -o www-data -g www-data /var/www/example.com
sudo -u www-data wp core download --path=/var/www/example.com
sudo -u www-data wp config create --path=/var/www/example.com \
  --dbname=wordpress --dbuser=wp --dbpass="$DB_PASS" --dbhost=localhost

WP-CLI may warn that it cannot write a cache directory for www-data; the download still works. Owning the files as www-data lets WordPress update itself from the dashboard. The stricter alternative is a separate owner with only wp-content/uploads writable by the web server, at the cost of running every update from the shell.

Configure the Nginx server block

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

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php;
    client_max_body_size 64m;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # uploads must never execute PHP
    location ~* ^/wp-content/uploads/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }

    # hide .git, .env and friends, keep ACME challenges reachable
    location ~ /\.(?!well-known) {
        deny all;
    }
}

client_max_body_size matches PHP's upload limit, so a large upload fails with a clear message instead of a vague error. Enable the site and drop the default one:

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

The Nginx, Apache and OpenLiteSpeed trade-offs are covered in Apache, Nginx or OpenLiteSpeed for a WordPress server if you are still choosing.

Add HTTPS

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

Certbot edits the server block to listen on 443, redirects plain HTTP, and installs a systemd timer that renews the certificate. The dry run proves renewal works before the first real expiry.

Run the installer, from the shell

Finish the install right away. An unfinished WordPress installer is open to whoever reaches it first, and they would become the site's administrator. WP-CLI does it in one command and prompts for the password, so it never lands in your shell history:

sudo -u www-data wp core install --path=/var/www/example.com \
  --url=https://example.com --title="Example" \
  --admin_user=siteadmin --admin_email=you@example.com \
  --prompt=admin_password

Choose any administrator name except admin, the first one bots guess.

Checks before launch

  1. Verify core files: sudo -u www-data wp core verify-checksums --path=/var/www/example.com should report success.
  2. Turn on pretty permalinks under Settings > Permalinks; the try_files line makes them work.
  3. Disable the built-in file editor: sudo -u www-data wp config set DISALLOW_FILE_EDIT true --raw --path=/var/www/example.com.
  4. Open Site Health under Tools > Site Health and fix anything marked critical.
  5. Test outgoing mail with a password reset. A fresh server has no mail transport, so install an SMTP plugin and send through a relay, as explained in Send email from your server.
  6. Plan backups before the first post: database dumps and wp-content, copied off the server. Back up your data off the server walks through restic.

Where everything lives

Write this map down now. When the site breaks at night, knowing which file to open is most of the fix.

Piece Location
Nginx server block /etc/nginx/sites-available/example.com
Nginx logs /var/log/nginx/access.log and error.log
PHP-FPM pool /etc/php/8.3/fpm/pool.d/www.conf
Your PHP overrides /etc/php/8.3/fpm/conf.d/90-wordpress.ini
PHP-FPM log /var/log/php8.3-fpm.log
WordPress files /var/www/example.com
Database settings and keys /var/www/example.com/wp-config.php
Database files /var/lib/mysql (back up with mariadb-dump, never by copying)
Certificates /etc/letsencrypt/live/example.com/

A request travels down that table: Nginx serves static files itself, passes .php requests to PHP-FPM through the Unix socket, WordPress runs and queries MariaDB, and the answer travels back the same way. A 502 error means the Nginx to PHP-FPM link failed; a database connection error means the WordPress to MariaDB link did.

Keep it updated

Three layers need updates, on different schedules:

  • The operating system: install unattended-upgrades so security fixes for Nginx, PHP and MariaDB arrive on their own, and reboot when a kernel update asks for it.
  • WordPress core: minor and security releases install automatically by default. Major releases wait for you; test them on a copy of the site first.
  • Plugins and themes: these cause most compromises. Remove what you do not use, update the rest weekly, and turn on automatic updates for plugins you trust.

From here, day-to-day work happens over SSH: updates, backups and fixes are covered in Manage WordPress over SSH with WP-CLI, and caching in Speed up WordPress on your own server.

FAQ

Can I follow this on Ubuntu 26.04?

Yes, with different version numbers. Ubuntu 26.04 ships PHP 8.5, MariaDB 11.8 and Nginx 1.28, so the php8.3-* packages become php8.5-*, the configuration path becomes /etc/php/8.5/, and the socket becomes php8.5-fpm.sock. Everything else in this guide stays the same.

Where do I put a second site?

Give it its own database and database user, its own directory and server block, and ideally its own PHP-FPM pool running as a separate system user, so a vulnerable plugin on one site cannot read the other's wp-config.php.

Should WordPress files be owned by www-data?

It is the convenient choice: dashboard updates and plugin installs work. If you update only through WP-CLI, a separate owner with write access limited to wp-content/uploads shrinks what a compromised plugin can change.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.