Shubham S Nimje logo
Shubham Nimje
LEMP Stack

Install the LEMP Stack on Ubuntu

Install the LEMP Stack on Ubuntu
2 min read
#LEMP Stack

Install the LEMP Stack on Ubuntu

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.

Prerequisites

  • 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

  • Syntax: ssh -p PORT USERNAME@HOSTIP
  • Example: ssh -p 22 raj@216.32.44.12

Instructions

1. Update and Upgrade the System

sudo apt update
sudo apt upgrade

2. Install Nginx

sudo apt install nginx
  • Allow Nginx through Firewall:
sudo ufw allow "Nginx Full"
  • Check Server IP on Web Browser: You should see the Nginx default page.

3. Install MySQL

sudo apt install mysql-server

4. Install PHP

sudo apt install php-fpm php-mysql
  • Packages Included:
    • php-fpm - To install PHP and PHP-FPM.
    • php-mysql - A PHP module that allows PHP to connect to MySQL.

5. Check PHP-FPM Status

sudo service php8.1-fpm status

OR

sudo systemctl status php8.1-fpm

6. Check Nginx Status

sudo service nginx status

OR

sudo systemctl status nginx

7. Start, Stop, and Manage Nginx

  • Start Nginx:
sudo service nginx start

OR

sudo systemctl start nginx
  • Stop Nginx:
sudo service nginx stop

OR

sudo systemctl stop nginx
  • Test Nginx Configuration:
sudo nginx -t

OR

sudo service nginx configtest
  • Reload Nginx:
sudo service nginx reload

OR

sudo systemctl reload nginx
  • Restart Nginx:
sudo service nginx restart

OR

sudo systemctl restart nginx