How to Install LEMP Server on Ubuntu 22.04

The LEMP stack, comprised of Linux, Nginx, MySQL, and PHP, is a robust solution for hosting dynamic websites and applications. In this guide, we’ll walk through the step-by-step process of setting up a LEMP server on Ubuntu 22.04. Follow these instructions carefully to establish a powerful web server environment.

Update and Upgrade System Packages

Begin by ensuring that your system is up-to-date. Open a terminal and execute the following commands:

sudo apt update
sudo apt upgrade -y

These commands will refresh the package lists and upgrade existing packages to their latest versions.

Install Nginx Web Server

Nginx is a high-performance web server known for its efficiency and speed. Install it with the following command:

sudo apt install nginx -y

This command installs Nginx on your system.

Install MySQL Server

MySQL serves as the relational database management system in our LEMP stack. Install it using the following command:

sudo apt install mysql-server -y

During the installation, you’ll be prompted to set a root password for MySQL. Choose a secure password and proceed.

Secure MySQL Installation

Enhance the security of your MySQL installation by running the MySQL Secure Installation script:

sudo mysql_secure_installation

Follow the on-screen instructions, addressing aspects such as setting the root password, removing anonymous users, and more. Respond with ‘y’ for yes and ‘n’ for no based on your preferences.

Install PHP and PHP-FPM

PHP, coupled with PHP-FPM, is essential for server-side scripting in the LEMP stack. Install PHP and the necessary modules with the following command:

sudo apt install php-fpm php-mysql -y

This command installs PHP along with PHP-FPM and the required modules for seamless communication with MySQL.

You’ve successfully established a LEMP server on Ubuntu 22.04. This powerful stack provides a solid foundation for hosting a variety of web applications and dynamic websites. To verify your setup, create a simple PHP file in the Nginx web root directory and access it through your web browser.

 

About the author

Technical Sahil

Hello I’m Sahil, May be most of you guys know me as Technical Sahil on YouTube. Founder of Hostrigger & Mailracle and running several other things online.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *