How To Set Up LEMP Stack On Ubuntu 20.04

We’ll set up the LEMP stack on Ubuntu 20.04 in this post. Ubuntu 20.04 LTS, also known as Focal Fossa. Ubuntu 20.04 is a popular choice for both desktop and server use.

It is stable, secure, and has wide software availability. LEMP stands for Linux, Nginx, MySQL, and PHP. Linux serves as the operating system for the server.

MySQL functions as the database system responsible for storing website and user data. PHP, on the other hand, acts as the server-side scripting language, facilitating dynamic processing.

Why choose the LEMP stack on Ubuntu 20.04 

  1. LEMP is widely adopted and well-supported. Numerous online tutorials and resources are available to assist you in starting with LEMP. Additionally, a large community of users can provide support should any issues arise.
  2. NGINX excels in speed and efficiency. As a fast and efficient web server, NGINX is highly scalable and capable of handling substantial traffic loads.
  3. MySQL provides power and reliability for databases. MySQL is a robust and dependable database system known for its scalability and straightforward backup and restoration processes.
  4. PHP is a versatile and widely used scripting language. PHP is utilized by many popular web applications like WordPress, Drupal, and Joomla, owing to its versatility and popularity.
  5. Cost-effective. The LEMP stack comprises freely available and open-source software, eliminating licensing expenses.
  6. Ease of management. The LEMP stack is relatively straightforward to manage, even for beginners. Great tutorials and tools are accessible to assist you in getting started.
  7. Enhanced security. By following established security best practices, the LEMP stack can be configured to offer robust security measures, safeguarding your website or application.

Let’s set up the LEMP stack on Ubuntu 20.04  

Before you add any application to Ubuntu, you should update and upgrade the system. Enables applications to run smoothly.

Do this by running these codes:

  • sudo apt update
  • sudo apt upgrade

After a successful update and upgrade, the system is ready for installation. We’ll begin with the web server.

1. Install Nginx Web Server

Nginx will run your applications online. Nowadays, Nginx is widely recognized as a high-performance web server with extensive popularity. 

It also serves the purpose of a reverse proxy and caching server. Execute the provided command to install the Nginx web server. Start it and check the status.

  • sudo apt install nginx
  • sudo systemctl start nginx
  • sudo systemctl status nginx

2. Install MariaDB Database Server

MariaDB is a seamless replacement for MySQL. It was created by former MySQL team members concerned about Oracle potentially converting MySQL into a closed-source product. 

Use the provided command to install MariaDB on Ubuntu 20.04: Also, check the status;

  • sudo apt install mariadb-server mariadb-client
  • systemctl status mariadb

Add more security by adding this code and following the prompts given.

  • sudo mysql_secure_installation

 3. Install PHP7.4

PHP stands for PHP: Hypertext Preprocessor, a popular open-source server-side scripting language utilized in websites and web applications.

As a crucial component of the LEMP stack, PHP facilitates the generation of dynamic content on websites. 

It also serves as an intermediary between webpages and the database system, enabling the retrieval of data from the database and its presentation to website visitors. 

Additionally, PHP allows for the insertion, updating, and deletion of data within the database. Install it by:

  • sudo apt install php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl

Now let’s start it and check the status:

  • sudo systemctl start php7.4-fpm
  • systemctl status php7.4-fpm

That’s it; PHP is running well. Now we have to set up the server block.

4. Create a PHP File to Test your LEMP stack

Run these codes to add a .info code that we’ll use to test the server.

  • sudo nano /var/www/html/test.php
  • <?php phpinfo();

Once this is done, save and now test your file by

PHP LEMP stack on Ubuntu 20.04 

Now your LEMP stack is ready for use! Congratulations on successfully installing Nginx, MariaDB, and PHP7.4 on Ubuntu 20.04

Secure your server by deleting the info.php file immediately to prevent unauthorized access by potential hackers.

To conclude,

Setting up the LEMP stack on Ubuntu 20.04 is easy. LEMP stack is an excellent option for developing high-performance and dependable web applications.

Ubuntu 20.04 provides a solid foundation, while the individual components of the stack have undergone extensive testing and enjoy strong support.

Was this article helpful?

Related Articles

Leave A Comment?