How to Install LEMP Stack (Nginx, MariaDB, PHP8.4) on Ubuntu 25.10

LEMP Stack is a collection of open-source software used for hosting dynamic web applications and websites.
It stands for Linux, Nginx, MariaDB/MySQL, and PHP, all of which work together to serve web content efficiently.

Update the System

Before installing any packages, make sure your system is up to date.

apt update
apt upgrade -y

Install Nginx

Install the Nginx web server using:

apt install nginx -y

Once installed, enable and start Nginx:

systemctl enable nginx
systemctl start nginx
systemctl status nginx

Output:

root@server:~# systemctl enable nginx
systemctl start 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 Wed 2025-10-22 15:07:17 UTC; 15s ago
 Invocation: 1aa7895860b34b77ac628f87de8761d4
       Docs: man:nginx(8)
   Main PID: 9452 (nginx)
      Tasks: 3 (limit: 8799)
     Memory: 3M (peak: 7M)
        CPU: 82ms
     CGroup: /system.slice/nginx.service
             ├─9452 "nginx: master process /usr/sbin/nginx -g daemon on; master>
             ├─9454 "nginx: worker process"
             └─9455 "nginx: worker process"

Oct 22 15:07:17 server systemd[1]: Starting nginx.service - A high performance >

Check Nginx version:

nginx -v

Output:

nginx version: nginx/1.28.0 (Ubuntu)

Make Nginx the owner of the default web directory:

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

Verify by visiting your server’s IP in a browser:

http://your-server-ip

Note: Replace the4 IP_address with your actual IP Addres

images

Install MariaDB Server

Install MariaDB:

apt install mariadb-server mariadb-client mariadb-client-compat -y

Start and enable MariaDB:

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.3 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: >
     Active: active (running) since Wed 2025-10-22 15:13:12 UTC; 19s ago
 Invocation: e62a156fbbb34c5f8e1f8544db8abd00
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 10436 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 13 (limit: 58076)
     Memory: 93.1M (peak: 97.7M)
        CPU: 3.009s
     CGroup: /system.slice/mariadb.service
             └─10436 /usr/sbin/mariadbd

Secure the MariaDB installation:

mysql_secure_installation

During the setup:

  • Set a root password
  • Remove anonymous users
  • Disallow remote root login
  • Remove test databases
  • Reload privileges

Once complete, log in to MariaDB:

mariadb -u root -p

Exit MariaDB:

exit

Check version:

mariadb --version

Output:

mariadb from 11.8.3-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using  EditLine wrapper

Install PHP

Install PHP and required extensions:

sudo apt install -y php8.4-fpm php8.4-cli php8.4-common php8.4-mysql php8.4-curl php8.4-xml php8.4-zip php8.4-mbstring php8.4-bcmath php8.4-intl php8.4-gd
sudo systemctl enable --now php8.4-fpm
sudo systemctl status php8.4-fpm

Output:

root@server:~# sudo systemctl enable --now php8.4-fpm
sudo systemctl status php8.4-fpm
Synchronizing state of php8.4-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable php8.4-fpm
● php8.4-fpm.service - The PHP 8.4 FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php8.4-fpm.service; enabled; prese>
     Active: active (running) since Wed 2025-10-22 15:30:18 UTC; 3min 58s ago
 Invocation: 239c3897e9c545d18edfca59132eef6b
       Docs: man:php-fpm8.4(8)
   Main PID: 24883 (php-fpm8.4)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0.00>
      Tasks: 3 (limit: 8799)
     Memory: 33.2M (peak: 34.8M)
        CPU: 306ms
     CGroup: /system.slice/php8.4-fpm.service
             ├─24883 "php-fpm: master process (/etc/php/8.4/fpm/php-fpm.conf)"
             ├─24884 "php-fpm: pool www"
             └─24885 "php-fpm: pool www"

Configure Nginx for PHP-FPM

Remove the default configuration file:

rm /etc/nginx/sites-enabled/default

Create a new configuration file:

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;

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

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.4-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 {
        deny all;
    }
}

Test Nginx syntax:

nginx -t

If no errors, reload Nginx:

systemctl reload nginx

Test PHP

Create a test PHP file:

nano /var/www/html/info.php

Add the following code:

<?php phpinfo(); ?>

Open your browser and visit:

http://your-server-ip/info.php

Note: Replace the4 IP_address with your actual IP Addres

images

If you see the PHP information page, PHP-FPM is working correctly.
Remove the file afterward:

rm /var/www/html/info.php

Conclusion

You have successfully installed the LEMP Stack (Nginx, MariaDB, PHP 8.4) on Ubuntu 25.10.
Your system is now ready to host PHP-based web applications such as WordPress, Laravel, or Nextcloud.


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