How to Install LEMP Stack on an Ubuntu 14.04 VPS

What’s LEMP?

It stands for Linux, nginx (Pronounced Engine X), MySQL, PHP

LEMP stack is used for developing and deploying web applications, and it consists of: Linux operating system, Nginx(pronounced engine x) web server, MySQL relational database management system that stores site data and PHP for processing dynamic content.

In this tutorial we will show you how to install a LEMP stack on Ubuntu 14.04 systems.

Step 1 — Installing Nginx

Nginx is a very powerful and efficient web server that helps you show your web pages to the world( when it has decided to stop searching for cat pictures). First we’ll start with an update then we’ll install it:

sudo apt-get update
sudo apt-get install nginx

Step 2 — installing MySQL

Now let’s get to installing server packages for MySQL and a php5-mysql package:

sudo apt-get install mysql-server php5-mysql

The installer will ask you for a root(admin) password, which you’ll use for your MySQL root user.

Now that you’ve installed the software, you can run a security script to change whatever settings you don’t like.

sudo mysql_secure_installation

Step 3 — Installing PHP

First we need to install php5-fpm (fastCGI process manager) due to the fact that Nginx does not contain native PHP processing:

sudo apt-get install php5-fpm

Now, let’s configure the FPM implementation we just made. First we open the php5-fpm file:

sudo nano /etc/php5/fpm/php.ini

Ok, now set the value for cgi.fix_pathinfo from 1 to 0:


Save and close and restart the processor:

sudo service php5-fpm restart

Step 4 — Configuring Nginx Virtualhost

We’ll start by opening default configuration file:

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

And let’ start making some changes :

server {

    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;  /* we added to the index directive a index.php option */

    server_name server_domain_name_or_IP;  /* we modified the server_name directive to point to server's domain name or public IP address */

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

    error_page 404 /404.html;  /* define error processing */

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }/* added try_files directive to obstruct Nginx from passing bad requests to PHP for processing */

And as always, save and close and for restarting you can:

sudo service nginx restart

or restart just the FPM implementation we just configured like so:

sudo service php5-fpm restart

If you followed these steps you should have your LEMP stack installed successfully on your server, but let’s test out to see if all the mods we made really work.

First create a php file in our document root:

sudo nano /usr/share/nginx/html/info.php

… and paste this in:

Save and close then type into your browser :


And a PHP generated page should appear with info about your server.

Ok, now delete file because we don’t want to make it easy for malicious software to see our server settings:

sudo rm /usr/share/nginx/html/info.php

Hopefully this tutorial was of assistance. Don’t hesitate to leave your feedback.

Want to host your website on a VPS? Then check out our Linux VPS Plans, starting at 2GB RAM & 10GB SSD for only $5/mo.

Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
× Dracula Servers

Subscribe to DraculaHosting and get exclusive content and discounts on VPS services.