blog-image

Aug 23, 2024

27 min read

Simple Guide – How to Install LEMP on Ubuntu 24.04

Written by

Marc Chartouny
In this simple tutorial, I will walk you through how to install LEMP on Ubuntu 24.04 in a few steps. I have tested all the instructions on a brand new Ubuntu 24.04 server to make sure all the commands are working and ensure that the LEMP installation works as expected.

What is LEMP in Linux?

The LEMP (Linux, Nginx, MySQL, PHP) stack in Linux refers to a toolkit comprising of Linux as the operating system, Nginx (pronounced Engine-x) as the web server, MySQL (or MariaDB) as the database system, and PHP (or Perl/Python) as the scripting language. These components are commonly used for creating web applications.

What is a LEMP Stack Used for?

A LEMP stack is used for building and deploying dynamic PHP-based web applications. It combines Linux as the operating system, Nginx as the web server, MySQL for database management, and PHP (or Perl/Python) for server-side scripting. This stack offers a robust and efficient environment for developing scalable and high-performance web applications.

What Does LEMP Stack Stand for?

LEMP stands for "Linux, Nginx, MySQL, and PHP." Together, these software technologies can be used to create a fully-functional web application
  • Linux is the most popular, secure and open source operating system used in web servers.
  • Apache HTTP Server is a free and open-source web server that delivers web content through the internet.
  • MySQL is a relational database engine that allows you to store data and manage it.
  • PHP is a widely used open source and general purpose server side scripting language used mainly in web development to create dynamic websites and applications.
NOTE: In this tutorial, we’ll be using MariaDB— a backward compatible, drop-in replacement of the MySQL® Database Server. MariaDB was designed to maintain the same functionality while introducing new features and improvements. install lemp on ubuntu 24.04

Installing LEMP on Ubuntu 24.04

To install LEMP on Ubuntu 24.04, you'll first update the Ubuntu package index, then install the MariaDB database server and secure it, install Nginx, then install PHP and configure the Nginx web server to handle PHP processing.

Prerequisites for Installing LEMP on Ubuntu 24.04

  • Familiarity with the Linux command line.
  • An Ubuntu 24.04 server with a non-root user with sudo privileges. If you haven't noticed, we offer top-tier Ubuntu servers at the globe's best prices. Check out our offerings and get ready to be amazed 🤯.
Check out our How to access your server using SSH guide to learn how to access your server and create a sudo user.

Note

Want to skip these time-consuming technical steps? Our engineers have created a ready-to-use 1-click LEMP application. Just select one of our servers, choose LAMP from the App menu during checkout, and LEMP will be set up in minutes. However, if you prefer to learn how to do it yourself, keep reading.

Step 1: Update The Package Cache

Start by updating the packages in the package manager cache to the latest available versions using the following command:
sudo apt update

Step 2: Install the MariaDB Database Server

After updating our package cache, we will now install the MariaDB database server. We'll use MariaDB instead of MySQL because it includes more features and supports new storage engines, in addition to its high performance. To install MariaDB, execute the following command:
sudo apt install mariadb-server mariadb-client
Tap the y key then Enter to continue the installation. In the preceding command, you install two packages:
  • mariadb-server: The MariaDB database server which actually stores data.
  • mariadb-client: The MariaDB database client which allows you to interact with and manage the database server via the command line.
install lemp on ubuntu: mariadb Once the installation is finished, verify that the MariaDB database server is running properly by executing the following command to check out the MariaDB service status:
sudo service mariadb status
The output should show that the service is enabled and running: lemp stack installation: mariadb status Here, you can see that the service is active and running in the line "Active: active (running) ...".

Ensure That MariaDB Starts at Boot

To make sure that the MariaDB database server starts with the system at boot, use the enable subcommand of the systemctl command. To do so, execute the following command:
sudo systemctl enable mariadb.service
You should receive the following output:
Synchronizing state of mariadb.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mariadb

Securing The MariaDB Database Server

MariaDB comes with some unsafe default settings which may expose your database server to dangerous security vulnerabilities. It's recommended that you run a security script that comes with MariaDB to strengthen your database server and minimize the risk of database intrusions or breaches. To secure your MariaDB database server, execute the following command, where you will be presented with seven prompts: First, run the script:
sudo mysql_secure_installation
You’ll be asked for your current root password:
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
Tap Enter. Next, you'll be asked whether you want to use the unix_socket authentication method:
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

Switch to unix_socket authentication [Y/n] 
Tap Y to enable unix_socket authentication for better
Continue reading this article
by subscribing to our newsletter.
Subscribe now

Leave a Reply