Person Holding Smartphone while using Laptop

Install the LEMP Stack on Ubuntu

How to Install LEMP (Linux Nginx MySQL PHP) Stack

Harness the power and efficiency of the LEMP stack (Linux, Nginx, MySQL, PHP) for your web projects! This detailed guide walks you through installing LEMP on Ubuntu, providing a robust foundation for building high-performance web applications.


  • An Ubuntu server with root or sudo privileges.
  • Basic understanding of using the command line.
  • Access to your server via SSH.
  • To Get Access via SSH
Example:- ssh -p 22 raj@
  • Updates the package lists for Upgrades then Upgrade
sudo apt update
sudo apt upgrade
  • Install Nginx
sudo apt install nginx
  • Allow Apache through Firewall
sudo ufw allow "Nginx Full"
  • Check Server IP on Web Browser You will see Nginx Default Page
  • Install MySQL
sudo apt install mysql-server
  • Install PHP
sudo apt install php-fpm php-mysql
The above command includes three packages:-
php-fpm -  To Install PHP and php-fpm
php-mysql - It is a PHP module that allows PHP to connect to MySQL 
  • Check php-fpm is running
sudo service php8.1-fpm status
sudo systemctl status php8.1-fpm
  • Check Nginx Status
sudo service nginx status
sudo systemctl status nginx
  • Start Nginx
sudo service nginx start
sudo systemctl start nginx
  • Stop Nginx
sudo service nginx stop
sudo systemctl stop nginx
  • Test Nginx Config
sudo nginx -t
sudo service nginx configtest
  • Reload Nginx
sudo service nginx reload
sudo systemctl reload nginx
  • Restart Nginx
sudo service nginx restart
sudo systemctl restart nginx