Installing the LEMP stack (Linux, Nginx, MySQL, PHP) on Ubuntu 16.04

There have been dozens of postings regarding how to install the LAMP kit on Server. However, considerably less is known about LEMP. The difference is that the first option uses Apache, while the second employs . Let’s go over the installation and initial configuration in further detail. As an example, Ubuntu 16.04 is utilized.

How to install LEMP

Let’s get the server platform ready for more work by installing Nginx. We use to connect to the equipment and install it using regular operating system tools. The distribution can be found in the official repositories.

Let’s go ahead and open the Nginx start page in the browser: Enter the IP address in the program’s address bar. The following image should be displayed:

Screenshot #1. Successful installation.

If the image does not open, add lines to the settings. We enter the commands:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT


Port 80 will be opened. It adds Nginx to the firewall’s white list.

Now that the preliminary preparation is over, let’s move on to configuration.

1. Install the system.

LAMP makes use of MySQL, whereas LEMP makes use of MariaDB.

Except for the distribution method, both products are identical: MariaDB is free, but MySQL has limits.

We utilize the following software installation tools:

sudo apt-get install mariadb-server mariadb-client

During the operation, the package will require you to come up with a secret key for an account with administrator rights.

Important! The following rules are recommended – a minimum of 9 characters, capital letters, numbers and special characters.

At the end, we check the performance:

sudo systemctl status mariadb

The result is shown in the screenshot:

Screenshot #2. Status check.

2. We increase the level of the package:

sudo mysql_secure_installation

The command disables guest login to the database, for the superuser, eliminates temporary tables and updates permissions. 

3. The next step is to install . To install, use the apt-get utility. List of packages to be installed:

sudo apt-get install php7.2
sudo apt-get install php7.2-mysql
sudo apt-get install php7.2-curl
sudo apt-get installphp7.2-json
sudo apt-get installphp7.0-cgi
sudo apt-get installphp7.0 libapache2-mod-php7.0
sudo apt-get installphp7.0-xml

The process will take approximately 10 minutes. Additional actions are not required, follow the prompts of the wizard.

4. After installation, you can connect additional PHP modules. The list is available with the command:

apt-cache search php7

A list of commands with decryption will appear on the monitor. Select the required one and install using standard Ubuntu tools.

5. Connect the installed applications to each other. We type:

sudo apt-get install php-fpm php-mysql

When finished, open the PHP configuration file through the built-in vi utility. We find the line cgi.fix, and assign the value to zero. Red shows the path to php.ini:

Screenshot #4. Alteration.

Important! To make the line active, remove the semicolon at the beginning of the line.

Exit the utility after saving your modifications. Restart the php7.2-fpm service to implement the updated configuration. The entire procedure will take less than a minute.

6. Correct the Nginx configuration file:

sudo vi /etc/nginx/sites-available/default

We find a line called Index and add additional values:

index.php index.html index.htm index.nginx-.html

Screenshot #5. Add line.

If you want to change the server name, use the command:

server_name XXX

where XXX is an arbitrary name of the server part. In our example, we use the name LEMP.

Adding the ability to process PHP requests: remove the symbol “;” before the lines. In the image, this is marked with the numbers “3” and “4”:

Screenshot #6. Final configuration.

Save the changes and restart the service using standard OS tools.

This completes the setup. Let’s check.


Let’s open a test page for testing. Let’s create a test case:

vi /var/www/html/info.php

Let’s add information:

Close the editor and save. Open the browser, enter the IP address of the server platform with the info key:, where is the address.

If the configuration was successful, the page will display the following:

Screenshot #7. LEMP server installed.

Cloud deployments that are quick, inexpensive, and adaptable provides businesses with an easy-to-implement, quick, adaptive, and cost-effective cloud deployment solutions platform for building and scaling business assets in the cloud. Essentially, we transform cloud experiences into amazing concrete benefits that push business success for clients all over the world.


Welcome to the world of DomainRooster, where roosters (and hens) rule the roost! We're a one-stop shop for all your entrepreneurial needs, bringing together domain names and website hosting, and all the tools you need to bring your ideas to life. With our help, you'll soar to new heights and hatch great success. Think of us as your trusty sidekick, always there to lend a wing and help you navigate the sometimes-complex world of domain names and web hosting. Our team of roosters are experts in their fields and are always on hand to answer any questions and provide guidance. So why wait? Sign up today and join the ranks of the world's greatest entrepreneurs. With DomainRooster, the sky's the limit! And remember, as the saying goes, "Successful people do what unsuccessful people are not willing to do." So don't be afraid to take that leap of faith - DomainRooster is here to help you reach for the stars. Caw on!