LEMP Stack consists of Nginx web server, MariaDB / MySQL database, and PHP language, running on top of Linux operating system. It is the most widely used tech stack after LAMP Stack for hosting websites, blogs, etc.. used by small to enterprise organizations.
Nginx web server is a free, open-source, high-performance web server and is known for its stability, scalability, simple configuration, and low resource consumption.
LEMP is the acronym of
L – Linux Operating System
E – Nginx Web Server
M – MariaDB / MySQL Server
P – PHP language
You can follow the Step by Step guide to install Ubuntu 18.04.
Download the Nginx repository public signing key from the official website.
Add the Nginx public signing key to your system.
sudo apt-key add nginx_signing.key
Add Nginx repository to your system.
echo "deb [arch=amd64] http://nginx.org/packages/ubuntu/ bionic nginx" | sudo tee /etc/apt/sources.list.d/nginx.list echo "deb-src [arch=amd64] http://nginx.org/packages/ubuntu/ bionic nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list
Now, install Nginx package using the apt command.
sudo apt update sudo apt install -y nginx
Start the Nginx web service after the installation.
sudo systemctl start nginx
Test Nginx Web Server
To make sure Nginx web server installed correctly, we will now test it to see if it is working correctly. Open up a web browser and then go to the following web address.
You should see Nginx’s default page. This page confirms that the Nginx is successfully installed on the server.
Nginx’s default document root (where we place html or php files) is
/usr/share/nginx/html/ and the configuration files can be found under
Install MariaDB Server
Update the system repository index.
sudo apt update
Install the MariaDB server and the client by issuing the following command.
sudo apt install -y mariadb-server mariadb-client
MariaDB server should now be up and running. If not, start MariaDB server manually using the following command.
sudo systemctl start mariadb
Next, secure MariaDB server using the
Install PHP-FPM (PHP-FastCGI Process Manager), an alternative PHP FastCGI daemon for PHP. It can handle high loads of requests by maintaining a pool of PHP worker processes.
Install php-fpm by running the following command.
sudo apt install -y php-fpm php-mysql php-cli
Edit php.ini file according to the installed PHP version.
sudo nano /etc/php/7.2/fpm/php.ini
cgi.fix_pathinfo value to
By default, PHP-FPM listens on the socket. But, here, we will configure PHP-FPM use a TCP connection.
Open the file configuration file and change the parameter listen.
sudo nano /etc/php/7.2/fpm/pool.d/www.conf
listen = /run/php/php7.2-fpm.sock
listen = 127.0.0.1:9000
Restart PHP-FPM service.
sudo systemctl restart php7.2-fpm
Create Virtual Host with PHP-FPM Support
Let’s create a name-based virtual host to test the PHP-FPM support for the following details.
Domain Name : web.linuxbees.local
Document Root : /usr/share/nginx/html/web.linuxbees.local
Create a virtual host configuration file for the domain.
sudo nano /etc/nginx/conf.d/web.linuxbees.local.conf
Add the following content.
Create the document root directory for the virtual host.
sudo mkdir /usr/share/nginx/html/web.linuxbees.local
Place a PHP file onto the document root to test the created virtual host.
echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/web.linuxbees.local/index.php
Update the permission of the file.
sudo chown -R www-data:www-data /usr/share/nginx/html/web.linuxbees.local/
Restart the services.
sudo systemctl restart nginx sudo systemctl restart php7.2-fpm sudo systemctl enable php7.2-fpm
Test PHP-FPM support on the Virtual Host
Create a host entry for the domain (web.linuxbees.local) in the
/etc/hosts file or make an A record on DNS server for name resolution.
sudo nano /etc/hosts
A host will look something like below:
192.168.1.10 web.linuxbees.local web
Open a web browser and go to the website.
The page will look like below:
From the above screenshot, the PHP is working through FPM/FastCGI shown in the Server API line.
You can also check the support of MariaDB by scrolling the page further down.
You have successfully installed LEMP Stack on Ubuntu 18.04. Consider installing phpMyAdmin on Ubuntu 18.04 to manage MariaDB database over a web browser. Also, you can install Let’s Encrypt SSL certificate in Nginx on Ubuntu 18.04 for secure communication.