fbpx

Introduction

The LEMP stack is a popular software stack for web development and hosting. It includes four major components: Linux, Nginx, MySQL, and PHP. Each component serves a specific purpose in powering dynamic websites and web applications.

  1. Linux is the operating system that serves as the LEMP stack’s foundation. In this case, Ubuntu is a Linux distribution known for its stability, security, and usability.
  2. Nginx is a high-performance web server and reverses proxy server (pronounced “engine-x”). It is well-known for its ability to handle concurrent connections and serve static and dynamic content efficiently. In the LEMP stack, Nginx serves as the front-end web server, handling incoming web requests and forwarding them to the appropriate backend components.
  3. MySQL is a popular open-source relational database management system (RDBMS). It provides a stable and scalable platform for storing and managing structured data. MySQL serves as the database server in the LEMP stack, storing and retrieving data for web applications.
  4. PHP is a server-side scripting language that was created for web development. It allows the server to run dynamic code, generate HTML pages, and interact with the database. PHP is a scripting language that is used to create dynamic web applications when used with Nginx and MySQL.

These components work together to form a powerful and flexible stack for hosting and developing web applications. The underlying operating system is Linux, the web server is Nginx, database operations are handled by MySQL, and PHP supports dynamic web content generation.

You can create a robust and efficient environment for hosting and developing web applications by installing and configuring the LEMP stack on Ubuntu 22.04.

Step 1: Update the package index

The first step is to update the system. It’s a good idea to update the system’s package repository and upgrade existing packages to the latest versions before installing any packages. Open a terminal window and enter the following commands:

sudo apt update
sudo apt upgrade
Install LEMP stack on Ubuntu 22.04

Due to the complexity and scope of the changes being implemented, the process of upgrading can frequently take several minutes.

Step 2: Install the Nginx Web Server

Nginx, a high-performance web server, will be used to display web pages to your site visitors. Since we are using Ubuntu, we will use apt to install Nginx our first LEMP stack service:

sudo apt install nginx
Install the LEMP Stack Nginx Web Server

Press Y and ENTER to confirm that you want to install Nginx. After installation, run the following commands to start Nginx and enable it to start on boot:

sudo systemctl start nginx
sudo systemctl enable nginx
enable LEMP stack

When you enable a service, systemd will start it automatically at boot time or when the system enters a specific target or runlevel. This ensures that essential services are available and operational without the need for manual intervention.

To verify if Nginx was successfully installed on your Ubuntu server, enter your server’s IP address into your web browser to access Nginx’s default landing page:

Install the Nginx Web Server

Step 3: Install MySQL on Ubuntu

Following the successful installation of your web server, the next step is to install a database system to handle data storage and management for your website. MySQL is a well-known relational database administration system. Run the following command to install MySQL our second LEMP stack service:

sudo apt install mysql-server
Install MySQL on Ubuntu

When the installation is complete, it is recommended that you run the security script that comes with MySQL. This script will disable access to your database system and remove some insecure default settings. Run the following command to launch the interactive script:

sudo mysql_secure_installation

Continue with Y

sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

Now you have to choose your password level, we will go with 1.

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Set your new password

Please set the password for root here.

New password:

For the remaining questions, press Y and then ENTER at each prompt. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL recognizes the changes you’ve made right away.

After the installation, run the following commands to start MySQL and enable it to start on boot:

sudo systemctl start mysql
sudo systemctl enable mysql

Running sudo mysql grants you administrative access to the MySQL server, allowing you to perform administrative tasks such as creating or modifying databases, managing users and permissions, executing SQL queries, and performing other administrative actions.

Let’s move forward with the last software of our LEMP stack.

Step 4: Install PHP

PHP is a server-side scripting language that is commonly used to create dynamic web content. You’ve set up Nginx to serve your content and MySQL to store and manage your data. Now it’s time to install PHP with the following command:

sudo apt install php8.1-fpm php-mysql

Continue with Y and check your PHP version after installation.

php -v
PHP 8.1.2-1ubuntu2.11 (cli) (built: Feb 22 2023 22:56:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.11, Copyright (c), by Zend Technologies

Final Thoughts

You have successfully installed the LEMP stack (Linux, Nginx, MySQL, and PHP) on Ubuntu 22.04. This powerful combination creates a dependable and efficient environment for hosting and developing web applications. With the LEMP stack installed, you can easily unlock your web development skills and create dynamic websites and web applications. Have fun coding!


1 Comment

How To Create A User And Grant Permissions In MySQL - Virtono Community · August 17, 2023 at 1:14 PM

[…] new users, giving them access, and, if necessary, deleting them. In this tutorial, we’ll examine MySQL’s user management procedure, which makes it the most widely used relational database management system available as […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.