How to Install WordPress on Ubuntu with Nginx, MariaDB and PHP (Complete LEMP Guide)

install wordpress ubuntu nginx - custom-wpinst-featured.png

Install WordPress on Ubuntu is among the highest-volume Linux hosting searches — bloggers, agencies, and small businesses moving off shared hosting all land on the same path: a VPS, a LEMP stack (Linux, Nginx, MariaDB, PHP), and the tarball from wordpress.org.

This is a full walkthrough from empty server to the installation wizard. Prerequisites are covered in our
PHP install guide,
MariaDB security, and
Certbot for HTTPS once DNS points at the box.

What You Are Building

Nginx serves static files and passes PHP to php-fpm. MariaDB stores posts and options. WordPress code lives under /var/www/yoursite owned by the web user.

LEMP for WordPress
architecture

Prepare the Server

Use Ubuntu LTS, create a sudo user, point your domain A record at the server IP, and patch the OS before installing stacks.

bashfirst login
sudo apt update && sudo apt upgrade -y
sudo ufw allow OpenSSH
sudo ufw enable
VPS prep
DNS and sudo

Install Nginx

Install the web server and allow HTTP/HTTPS through the firewall.

bashnginx
sudo apt install -y nginx
sudo systemctl enable --now nginx
sudo ufw allow 'Nginx Full'
nginx package
ufw

Install MariaDB

WordPress needs a MySQL-compatible server; MariaDB is the common Ubuntu default.

bashdatabase server
sudo apt install -y mariadb-server
sudo mysql_secure_installation
mariadb-server
secure install

Install PHP-FPM and Extensions

WordPress expects mysqli, curl, mbstring, xml, zip, and gd for media.

bashPHP for WP
sudo apt install -y php-fpm php-mysql php-curl php-mbstring php-xml php-zip php-gd
php -v
php-fpm
extensions

Create the WordPress Database

Use a dedicated database and user — not root — with grants only from localhost.

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

Download and Configure WordPress

Unpack under your web root, copy wp-config-sample.php to wp-config.php, and insert database credentials and unique salts from the WordPress salt generator.

bashdeploy files
sudo mkdir -p /var/www/example.com
 cd /tmp && wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz -C /var/www/example.com --strip-components=1
sudo chown -R www-data:www-data /var/www/example.com
wp-config.php
permissions

Nginx Virtual Host for WordPress

Pretty permalinks need try_files and a PHP location block pointing at the correct FPM socket.

nginx/etc/nginx/sites-available/example.com
server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php;
    location / { try_files $uri $uri/ /index.php?$args; }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }
}
server block
try_files

Verify, Harden, Add TLS

Complete the web installer, disable theme/plugin editor in wp-config.php if desired, schedule backups, then run Certbot.

bashenable site
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
TipAdd define('DISALLOW_FILE_EDIT', true); in wp-config on production sites.
go live
HTTPS

Quick Reference

  • Stack: Nginx + MariaDB + php-fpm
  • DB user with least privilege on one database
  • HTTPS: Certbot after DNS works

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.