LEMP is a group of software which is used to serve dynamic web pages and web application. LEMP is a variation of LAMP stack. When compare to LAMP stack in this Apache is replaced with lightweight powerful web server Nginx.

In this tutorial we will show how to set up a LEMP in Ubuntu 16.04

Step 1

We will be setting one of the most lightweight yet powerful web server Nginx. Nginx is a open-source reverse proxy server which support HTTP, HTTPS,SMTP, POP3, and IMAP protocols. It also function as load balancer and HTTP cache. it focus on high concurrency, high performance and low memory usage.

sudo apt-get update
sudo apt-get install nginx

Once this is installed you can access the same with below

http://domain_name or IP Address or local-host



Step 2

In this we can setup database MySQL. The second most widely used relational database management system.You can install MySQL as follow

sudo apt-get install mysql-server

You will be asked to setup a root user credentials with password. Once the set up is done you have to secure the MySQL DB with below command

sudo mysql_secure_installation

You will be asked to reset root password and set VALIDATE PASSWORD PLUGIN. This is purely users choice to make better password strength.Password which does not satisfy specified criteria will be rejected by MySQL with an error.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:


If you press YES

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Once root password is set It will ask


* Remove root accounts that are accessible from outside the local host
* Remove anonymous-user accounts
* Remove the test database


Step 3

In this we will setup PHP which is a server side scripting language designed for web development.We will grab php with below command

sudo apt-get install php-fpm php-mysql


Configuring PHP

First we need to set up php-fpm

sudo vim /etc/php/7.0/fpm/php.ini

set cgi.fix_pathinfo=0

sudo systemctl restart php7.0-fpm


Configure Nginx with PHP

For Nginx to use the PHP Processor for dynamic content.

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

server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
try_files $uri $uri/ =404;

We can modify this as


server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;

server_name domain name or IP;

location / {
try_files $uri $uri/ =404;

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;

location ~ /\.ht {
deny all;



Once the setting is done you can test your configuration with

sudo nginx -t

Reload the server
sudo systemctl reload nginx

Test PHP

Create a info page with below command

sudo vim /var/www/html/info.php




http://domain_name or IP Address or local host/info.php

you will get php info page as below if you successfully set up PHP


Now you have a LEMP stack configured on ubuntu 16.04 !!!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: