A LEMP stack — Linux, Nginx, MySQL, and PHP — is a popular open-source web platform for hosting dynamic websites and web applications. This guide installs and configures all four components on Ubuntu 26.04 LTS.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS server
- A user with sudo privileges
- UFW firewall enabled
Step 1 – Install Nginx
sudo apt update
sudo apt install nginx -y
sudo ufw allow 'Nginx Full'
Step 2 – Install MySQL 9
sudo apt install mysql-server -y
Run the security script:
sudo mysql_secure_installation
Step 3 – Install PHP 8.4
Install PHP with Nginx FPM support and common extensions:
sudo apt install php8.4-fpm php8.4-mysql php8.4-mbstring php8.4-xml php8.4-curl php8.4-zip -y
Step 4 – Configure Nginx to Use PHP
Create a server block that passes PHP requests to FPM:
sudo nano /etc/nginx/sites-available/default
Ensure the location block for PHP looks like:
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
Step 5 – Test the Configuration
sudo nginx -t
sudo systemctl reload nginx
Step 6 – Test PHP Processing
Create a PHP info file to verify the stack:
echo '' | sudo tee /var/www/html/info.php
Visit http://your_server_ip/info.php. Remove the file after testing:
sudo rm /var/www/html/info.php
Step 7 – Test Database Connectivity
Log into MySQL to confirm it’s working:
sudo mysql
SHOW DATABASES;
exit
Conclusion
Your LEMP stack on Ubuntu 26.04 LTS is fully operational. You can now host PHP applications backed by MySQL, served through Nginx with PHP-FPM for high-performance request handling.