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

Ubuntu 16.04 is no longer supported, so this guide now uses Ubuntu 24.04 LTS (Debian 12 works the same way).

LEMP is Linux, Nginx ("engine-x"), MariaDB and PHP-FPM. Nginx serves static files very efficiently and passes PHP to PHP-FPM.

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.

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

Create a database

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

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/app;
    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.

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.

Test with a phpinfo() file in the web root, then delete it.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket