Complete LEMP Stack Setup on Ubuntu 24.04 LTS: Nginx, MariaDB & PHP 8.3 FPM
Mir Alamin
Principal Web Architect
Complete LEMP Stack Setup on Ubuntu 24.04 LTS: Nginx, MariaDB & PHP 8.3 FPM
Author: Mir Alamin (Principal Web Architect) | Published: August 2, 2026 at 10:30 AM | Reading Time: 22 min read | Category: Architecture | Tags: LEMP setup, Nginx, Ubuntu Server Update, PHP 8.3, MariaDB, Web Server
Executive Summary
The LEMP stack—comprising Linux (Ubuntu 24.04 LTS), Nginx (Engine-X), MariaDB (or MySQL), and PHP-FPM—forms the backbone of high-concurrency web servers worldwide. Unlike traditional LAMP stacks using Apache's process-per-request mpm_prefork model, Nginx relies on an asynchronous, event-driven architecture capable of handling over 10,000 concurrent connections with minimal RAM footprint.
This guide provides a production-grade, step-by-step walkthrough for deploying, configuring, and hardening a LEMP stack on fresh Ubuntu 24.04 Noble Numbat servers.
1. Updating Ubuntu 24.04 LTS & Preparing Repository Sources
Prior to installing web stack packages, update system package indexes and upgrade core server packages to ensure all security patches are applied.
# Update package repositories and upgrade existing packages
sudo apt update && sudo apt dist-upgrade -y
# Install essential server tools and utilities
sudo apt install -y curl wget unzip software-properties-common ufw htop net-tools ca-certificates
# Reboot if kernel updates were applied
sudo reboot
2. Installing & Configuring Nginx Web Server
Install Nginx from official Ubuntu repositories and configure non-blocking worker processes.
# Install Nginx web server
sudo apt install -y nginx
# Verify Nginx status and enable on boot
sudo systemctl enable --now nginx
sudo systemctl status nginx
Configuring UFW Firewall for Nginx:
# Allow HTTP (Port 80) and HTTPS (Port 443) through UFW firewall
sudo ufw allow 'Nginx Full'
sudo ufw allow OpenSSH
sudo ufw enable
3. Installing & Securing MariaDB Database Server
MariaDB 10.11+ is the default relational database engine shipped with Ubuntu 24.04 LTS.
# Install MariaDB server and client
sudo apt install -y mariadb-server mariadb-client
# Enable MariaDB daemon
sudo systemctl enable --now mariadb
# Execute interactive security hardening wizard
sudo mariadb-secure-installation
During mariadb-secure-installation:
- Set a strong root database password.
- Remove anonymous user accounts.
- Disallow remote root login.
- Drop the test database.
- Reload privilege tables.
4. Installing PHP 8.3 FPM & Core Extensions
PHP 8.3 provides substantial JIT compiler optimizations and memory efficiency improvements over PHP 8.1/8.2.
# Add Ondřej Surý PHP repository for modern PHP builds
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
# Install PHP 8.3 FPM and common extensions required for CMS engines
sudo apt install -y php8.3-fpm php8.3-cli php8.3-common php8.3-mysql php8.3-mbstring php8.3-xml php8.3-gd php8.3-curl php8.3-zip php8.3-bcmath php8.3-intl php8.3-opcache php8.3-imagick
Verify PHP-FPM socket service execution:
sudo systemctl status php8.3-fpm
5. Crafting an Optimized Nginx Server Block for PHP 8.3
Create a server block definition located at /etc/nginx/sites-available/example.com:
# /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/public;
index index.php index.html index.htm;
# Gzip Compression Settings
gzip on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
# Security Headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Pass PHP scripts to PHP-FPM unix socket
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
# Deny access to hidden files (.htaccess, .git, .env)
location ~ /\. {
deny all;
}
# Static asset caching
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf)$ {
expires 365d;
add_header Cache-Control "public, no-transform";
}
}
Enable site definition and test syntax:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
6. Managed Server Administration & Speed Optimization Services
If you need veteran engineers to set up, optimize, or migrate your enterprise LEMP stack, explore my specialized web services:
- ⚙️ Managed Server Administration Plans
- 🚀 Website Speed Optimization Services
- 🔄 Zero Downtime Website Transfer Services
7. Frequently Asked Questions (FAQ)
Q1: Why is PHP-FPM preferred over mod_php in Nginx environments?
Nginx cannot process dynamic scripting languages natively. PHP-FPM operates as an independent FastCGI daemon listening on a UNIX socket or TCP port, keeping web server worker processes lightweight and isolated.
Q2: How do I obtain a free SSL certificate for my LEMP server?
Use Let's Encrypt Certbot: sudo apt install certbot python3-certbot-nginx -y followed by sudo certbot --nginx -d example.com -d www.example.com.
© 2026 WebCare Pro. Authored by Mir Alamin.
Was this engineering analysis helpful?
Leave feedback to help us refine our technical content.
Share with fellow developers
Found value in this guide? Share it across your network.
Written by Mir Alamin
Principal Web Architect at WebCare Pro. Specializing in Next.js speed optimizations, high-score Core Web Vitals, Cloudflare Workers static edge hosting, and continuous website maintenance.
Explore WebCare Pro ServicesMore in Architecture
View Category →High-Performance Static Web Architecture: Next.js SSG & Cloudflare Pages Edge Deployment
Architect blazing fast static web apps using Next.js output export, Cloudflare Pages edge deployment, and zero-runtime serverless functions.
Optimizing PHP-FPM for High-Memory WordPress Multisite on Nginx
Configure isolated PHP-FPM process pools, custom memory limits, and Nginx rewrite rules for high-concurrency WordPress Multisite networks.