In this tutorial, we will show you how to install LEMP on Ubuntu 20.04 LTS. For those of you who didn’t know, A LEMP software stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Nginx webserver (which replaces the Apache component of a LAMP stack). The site data is stored in a MySQL database (using MariaDB), and dynamic content is processed by PHP.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you through the step by step installation LEMP stack on an Ubuntu 20.04 (Focal Fossa) server.
Install LEMP on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running these following
apt commands in the terminal.
Step 2. Installing Nginx on Ubuntu 20.04.
Nginx is a high-performance web server and very popular these days. It also can be used as a reverse proxy and caching server. Run the following command from the Terminal to install Nginx webserver:
Once installed, check to see if the Nginx service is running:
Now if you have your UFW firewall running, you will need to allow connections to Nginx:
Check the firewall status:
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
NginxFull ALLOW Anywhere
OpenSSH(v6) ALLOW Anywhere(v6)
NginxFull(v6) ALLOW Anywhere(v6)
Let us go ahead and run Nginx test page. Go to your web browser and visit your domain or IP:
Step 3. Installing MariaDB on Ubuntu 20.04.
MariaDB is a drop-in replacement for MySQL. It is developed by former members of MySQL team who are concerned that Oracle might turn MySQL into a closed-source product. Run the following command to install MariaDB:
Once complete, you can verify MariaDB is installed by running the below command:
By default, MariaDB is not hardened. You can secure MariaDB using the
mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
Configure it like this:
To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MariaDB database):
Unlike Apache, Nginx does not contain native PHP processing. For that, we have to install PHP-FPM (FastCGI Process Manager). Run the following command to install PHP7.4 and some common extensions:
Once installed, check the PHP version:
Next, configuring Nginx to work with PHP-FPM:
Paste the following text into the file:
# A long browser cache lifetime can speed up repeat visits to your page
# disable access to hidden files
Then, test the Nginx configuration syntax for correctness. If it is OK, restart the Nginx service to apply the new changes:
To test PHP, create a test file named info.php with the content below. Save the file, then browse to it to see if PHP is working:
Copy the following into your text editor:
Try to access it at
http://your_server_ip/info.php. If the PHP info page is rendered in your browser then everything looks good and you are ready to proceed further.
Congratulations! You have successfully installed LEMP stack. Thanks for using this tutorial for installing LAMP (Linux, Nginx, MariaDB and PHP) in Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you to check the official Nginx, MySQL and PHP web site.