Web Servers & Stacks Intermediate 15 min

How to Install Linux, Nginx, MariaDB, PHP (LEMP Stack) on Ubuntu 24.04 LTS

Complete step-by-step guide to installing a production-ready LEMP stack with PHP 8.3 and secure MariaDB

IndSoft Cloud Engineering
Reviewed October 2026
Production Verified Commands

Guide Overview & Architecture Outcome

By following this guide, you will have a fully functioning LEMP stack (Linux, Nginx, MariaDB, PHP 8.3) configured for production performance on an Ubuntu 24.04 server. You will be able to serve high-speed dynamic web applications with automated process management and database support.

Prerequisites & System Requirements

An Ubuntu 24.04 server with at least 1 GB RAM, non-root user with sudo privileges, and a registered domain name pointing to your server's IP address. Recommended platform: IndSoft Standard VPS (2 vCPU, 2GB RAM).

1

Update Package Repository and Install Nginx

Start by synchronizing your system's package indices and installing the latest stable Nginx web server.

bash · step-1-command.sh
sudo apt update && sudo apt upgrade -y sudo apt install nginx -y
Expected System Output:
Setting up nginx (1.24.0-2ubuntu7) ... Processing triggers for ufw ... Starting Nginx HTTP and reverse proxy server... [ OK ]
2

Adjust UFW Firewall for Web Traffic

Ensure the Uncomplicated Firewall (UFW) permits incoming HTTP (port 80) and HTTPS (port 443) traffic.

bash · step-2-command.sh
sudo ufw allow 'Nginx Full' sudo ufw status
Expected System Output:
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx Full ALLOW Anywhere
3

Install MariaDB Database Server and Secure It

Install the MariaDB relational database management system and execute the security script.

bash · step-3-command.sh
sudo apt install mariadb-server -y sudo mysql_secure_installation
Expected System Output:
Success. All done! If you've completed all of the above steps, your MariaDB installation should now be secure.
4

Install PHP 8.3 and Required FastCGI Extensions

Install PHP 8.3 along with the PHP-FPM FastCGI process manager and MySQL driver modules.

bash · step-4-command.sh
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip -y
Expected System Output:
Setting up php8.3-fpm (8.3.6-0ubuntu0.24.04.1) ... Creating config file /etc/php/8.3/fpm/php.ini with new version NOTICE: PHP message: PHP-FPM is running and ready to handle connections
5

Configure Nginx to Use the PHP FastCGI Processor

Create a server block configuration under /etc/nginx/sites-available/example.com to process .php files via unix socket.

bash · step-5-command.sh
sudo nano /etc/nginx/sites-available/example.com # Add server block with: # location ~ \.php$ { # include snippets/fastcgi-php.conf; # fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; # } sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx
Expected System Output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

Check That It Worked (Verification)

Run this quick verification check to confirm your installation is responding properly:

verify-service.sh
curl -I http://localhost
Expected Response:
HTTP/1.1 200 OK Server: nginx/1.24.0 Date: Mon, 14 Oct 2026 12:00:00 GMT Content-Type: text/html Connection: keep-alive

Troubleshooting Common Errors

Quick resolutions for frequent setup pitfalls and configuration issues.

Diagnostic Tips
Nginx returns '502 Bad Gateway'
Verify that the PHP-FPM service is running and matches the socket path: sudo systemctl status php8.3-fpm. Ensure /var/run/php/php8.3-fpm.sock exists.
MariaDB Access Denied for User 'root'@'localhost'
Ubuntu MariaDB defaults to unix_socket authentication for root. Use sudo mariadb directly without a password parameter.
Firewall blocking port 80/443
Run sudo ufw status verbose and ensure 'Nginx Full' is permitted on active interfaces.