The LEMP stack — Linux, Nginx, MySQL, and PHP — is a popular combination for hosting dynamic web applications. This guide installs and integrates all four components on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- A user with sudo privileges
- UFW firewall configured
Step 1 – Install Nginx
Install and enable Nginx:
sudo apt update
sudo apt install nginx -y
sudo systemctl enable nginx
sudo ufw allow 'Nginx Full'
Step 2 – Install MySQL
Install the MySQL 8.0 server:
sudo apt install mysql-server -y
Secure the installation:
sudo mysql_secure_installation
Step 3 – Install PHP 8.3 and Required Extensions
Add the Ondrej PPA for the latest PHP and install PHP-FPM:
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php8.3-fpm php8.3-mysql php8.3-mbstring php8.3-xml php8.3-curl php8.3-zip php8.3-gd -y
Step 4 – Configure Nginx to Use PHP-FPM
Create a test server block:
sudo nano /etc/nginx/sites-available/default
Add the PHP location block inside the server block:
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
Step 5 – Test the Nginx Configuration
Validate and reload:
sudo nginx -t
sudo systemctl reload nginx
Step 6 – Test PHP Processing
Create a PHP info file:
echo '' | sudo tee /var/www/html/info.php
Visit http://your_server_ip/info.php — you should see the PHP info page. Remove afterwards:
sudo rm /var/www/html/info.php
Step 7 – Create a MySQL Database and User
Log into MySQL and create a database:
sudo mysql
CREATE DATABASE mydb;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Conclusion
Your Ubuntu 24.04 LTS LEMP stack is ready. Nginx serves requests, PHP 8.3-FPM processes scripts, and MySQL 8.0 stores data. You can now deploy any PHP-based application such as WordPress or Laravel.