Search

How to Set Up LEMP Stack on Ubuntu 24.04 LTS

Share it

The LEMP stack, composed of Linux, Nginx, MariaDB, and PHP, is robust open-source software that serves as the foundation for numerous web applications.

If you’ve opted for Ubuntu 24.04 as your server platform, well done! It’s renowned for its security and dependability. Before we proceed, let’s delve a bit deeper into the other three components.

  • Nginx: Often referred to as “Engine-X,” Nginx is a high-performance web server celebrated for its stability, efficient management of concurrent connections, and minimal resource consumption.
  • MariaDB: A free, community-driven fork of MySQL, MariaDB is the database management system of choice in this iteration of the LEMP stack. It frequently includes new features and enhancements not found in MySQL, focusing on performance and security.
  • PHP: A prevalent general-purpose scripting language optimized for web development. PHP generates dynamic content on web pages in the LEMP stack and integrates smoothly with Nginx and MariaDB.

In the sections below, we’ll walk you through the setup process, configuration settings, and essential operational commands, ensuring you have a fully operational LEMP server on your Ubuntu 24.04 LTS (Noble Numbat) system by the end of this guide. Let’s kick things off!

Prerequisites:

  • A server running Ubuntu 24.04 LTS.
  • Root access to the server or a user with sudo privileges.
  • Familiarity with Linux commands and the terminal.

Step 1: Refresh Your System

Before installing any new packages, it’s always wise to update your package list using the well-known APT command and upgrade the existing ones to the latest version.

If there are updates pending, I recommend applying them before proceeding. You can achieve this by executing:

sudo apt update
sudo apt upgradeCode language: Bash (bash)
Refresh software repositories.

Step 2: Deploy the Nginx Web Server

The web server facilitates the delivery of content, such as web pages, to visitors. Employ the following commands to install the most recent version of Nginx on your Ubuntu 24.04 system. When prompted, confirm by typing “Y.”

sudo apt install nginxCode language: Bash (bash)
Deploy the Nginx web server on Ubuntu 24.04 LTS.
Deploy the Nginx web server on Ubuntu 24.04 LTS.

Following installation, Nginx automatically starts running in the background on your Ubuntu server. To verify its functionality, open a web browser and enter the server’s IP address in the address bar. You should be greeted by Nginx’s default welcome page.

Nginx's default welcome page.
Nginx’s default welcome page.

If you encounter difficulty accessing the page, the UFW (Uncomplicated Firewall) may be active, although it isn’t the default setting in Ubuntu 24.04. To check its status, run:

sudo ufw statusCode language: Bash (bash)
Check firewall status.
Check firewall status.

If the “Status” line indicates “active,” the UFW firewall is enabled, and access is restricted. To permit client requests to reach Nginx on ports 80 (HTTP) and 443 (HTTPS), run the subsequent command:

sudo ufw allow "Nginx Full"Code language: Bash (bash)
Allowing HTTP and HTTPS ports on Ubuntu.
Allowing HTTP and HTTPS ports on Ubuntu.

In this scenario, “Nginx Full” references a UFW configuration enabling access to both ports 80 and 443. Alternatively, you can specify “Nginx HTTP” to allow access only to port 80, or “Nginx HTTPS” for port 443.

To list all currently installed applications on your Ubuntu 24.04 system that can be managed with UFW, execute the following command:

sudo ufw app listCode language: Bash (bash)
UFW apps list.
UFW apps list.

Step 3: Install MariaDB Database Server

MariaDB, a community-driven fork of MySQL, serves as the database server in the LEMP stack. To install it, execute the commands below, confirming installation by typing “Y” when prompted and pressing “Enter.”

sudo apt install mariadb-serverCode language: Bash (bash)
Install MariaDB Server on Ubuntu 24.04 LTS.
Install MariaDB Server on Ubuntu 24.04 LTS.

Following installation, it’s crucial to run the security script provided with MariaDB to configure initial settings and secure the instance:

sudo mysql_secure_installationCode language: Bash (bash)

Upon running the above command, you’ll be prompted to enter the MariaDB root password. Leave this password empty and press “Enter.” Follow the prompts, continuing to type “Y” and pressing “Enter” to eliminate anonymous users, disallow remote root login, and delete the test database.

The crucial step is setting the root password for the MariaDB server. Ensure to select a secure password and re-enter it for verification. The password will not be visible on screen as you type.

Securing MariaDB server’s installation.

🤞 Don’t miss these tips!

🤞 Don’t miss these tips!

Solverwp- WordPress Theme and Plugin