How to Install LEMP Stack (Nginx, MariaDB, PHP) on Ubuntu 26.04

LEMP Stack is a combination of free, open source software. The acronym LEMP refers to the first letters of Linux (Operating system), Nginx Server, MySQL (database software), and PHP, PERL or Python, principal components to build a viable general purpose web server.

Updating the system

We first update the system to make sure that all our installed packages are up to date. Your Ubuntu system can be updated easily with the following command.

apt update
apt upgrade

Install Nginx

Start by installation of the Nginx web server. To complete the installation, use the below command.

apt install nginx -y

Output:

root@vps:~# apt install nginx -y
Installing:
  nginx

Installing dependencies:
  nginx-common

Summary:
  Upgrading: 0, Installing: 2, Removing: 0, Not Upgrading: 0

Once the installation is complete, enable Nginx (to start automatically upon system boot), start the webserver, and verify the status using the commands below.

systemctl start nginx
systemctl enable nginx
systemctl status nginx

Output:

root@server:~# systemctl start nginx
systemctl enable nginx
systemctl status nginx
Synchronizing state of nginx.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: en>
     Active: active (running) since Fri 2026-04-24 18:53:29 UTC; 41s ago
 Invocation: 10e8d60d2b2448e1bf6053fd822705ba
       Docs: man:nginx(8)
   Main PID: 2054 (nginx)
      Tasks: 3 (limit: 8826)
     Memory: 3M (peak: 7M)
        CPU: 116ms
     CGroup: /system.slice/nginx.service
             ├─2054 "nginx: master process /usr/sbin/nginx -g daemon on; master>
             ├─2057 "nginx: worker process"
             └─2058 "nginx: worker process"

Check the Nginx version,

nginx -v

Output:

root@server:~#     nginx -v
nginx version: nginx/1.28.3 (Ubuntu)

We need to make the user Nginx the owner of the web directory. By default, it’s owned by the root user.

chown www-data:www-data /usr/share/nginx/html -R

Verify that the webserver is running and accessible by accessing your server’s IP address. From your browser,

http://IP_address

Note: Replace IP_address with your actual IP Address

image

Install MariaDB Server

MariaDB is a popular database server. The installation is simple and requires just a few steps as shown.

apt install mariadb-server mariadb-client -y

Once the installation is complete, enable MariaDB (to start automatically upon system boot), start the MariaDB, and verify the status using the commands below.

systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb

Output:

root@server:~#     systemctl start mariadb
    systemctl enable mariadb
    systemctl status mariadb
Synchronizing state of mariadb.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable mariadb
● mariadb.service - MariaDB 11.8.6 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: >
     Active: active (running) since Fri 2026-04-24 18:57:31 UTC; 23s ago
 Invocation: 2496c07254024892b4fcb2f9d094bbdc
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 3069 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 14 (limit: 58255)
     Memory: 93.5M (peak: 97.9M)
        CPU: 3.694s
     CGroup: /system.slice/mariadb.service
             └─3069 /usr/sbin/mariadbd

Secure your MariaDB installation by removing vulnerabilities and setting essential restrictions.

mariadb-secure-installation

This script helps you improve the security of your MariaDB server by:

  • Setting a root password
  • Removing anonymous users
  • Disabling remote root login
  • Removing test database
  • Reloading privilege tables

Once secured, you can login to MariaDB using below command,

mariadb -u root -p

To exit from MariaDB.

exit

Check MariaDB Version,

mariadb --version

Install PHP

PHP 8.5 is the default version of PHP that would be installed on Ubuntu 26.04.

Install PHP and Required Extensions using below command,

apt install php-fpm php-mysql php-mbstring php-gd php-xml php-curl php-zip -y

Start and enable php8.5-fpm

systemctl start php8.5-fpm
systemctl enable php8.5-fpm

Check status of php8.5-fpm

systemctl status php8.5-fpm

Output:

   root@server:~# systemctl status php8.5-fpm
● php8.5-fpm.service - The PHP 8.5 FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php8.5-fpm.service; enabled; prese>
     Active: active (running) since Fri 2026-04-24 19:04:58 UTC; 48s ago
 Invocation: 3347e4e7ab9b429ebe055c883a63dd78
       Docs: man:php-fpm8.5(8)
   Main PID: 16290 (php-fpm8.5)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0.00>
      Tasks: 3 (limit: 8826)
     Memory: 11M (peak: 13M)
        CPU: 202ms
     CGroup: /system.slice/php8.5-fpm.service
             ├─16290 "php-fpm: master process (/etc/php/8.5/fpm/php-fpm.conf)"
             ├─16291 "php-fpm: pool www"
             └─16292 "php-fpm: pool www"

Setting Up Server Blocks

You need to remove the default file located in /etc/nginx/sites-enabled.

rm /etc/nginx/sites-enabled/default

Create new server block file under /etc/nginx/conf.d/ directory.

nano /etc/nginx/conf.d/default.conf

Add the following configuration:

server {
    listen 80;
    listen [::]:80;
    server_name _;
    root /var/www/html/;
    index index.php index.html index.htm index.nginx-debian.html;

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

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.5-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        include snippets/fastcgi-php.conf;
    }

    location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
        access_log off;
        log_not_found off;
        expires 360d;
    }

    location ~ /\.ht {
        access_log off;
        log_not_found off;
        deny all;
    }
}

Next, test to make sure that there are no syntax errors in any of your Nginx files.

nginx -t

Restart Nginx to enable your changes

systemctl reload nginx

Test PHP-FPM with the Nginx Web server, we need to create an info.php file in the webroot directory.

nano /var/www/html/info.php

Add the following PHP code to the file.

<?php phpinfo(); ?>

Now access:

http://yourserver-ip-address/info.php

You should see the PHP info page.

images

This concludes the installation of LEMP Stack on Ubuntu 26.04 server.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS