Verified and Tested 10/26/15

Introduction

This how-to will go through the process of installing at LEMP stack on Ubuntu 15.10. LEMP is very similar to LAMP, with one significant difference, you are installing NGINX instead of Apache. NGINX development has focused on performance, which is why many are beginning to migrate to NGINX web servers and away from Apache. This guide will still be using MySQL and PHP.

Prerequisites

A server with Ubuntu 15.10 installed. If you don’t have a server and would like one, try one of our reliable SSD Cloud Servers

Installing LEMP on a Ubuntu 15.10 Cloud Server Or VPS

First we want to make sure that your server is up to date by running the commands:

sudo apt-get update

Note: Depending on your installation you may need to remove apache2. You can do that by running the commands:

sudo apt-get remove apache2*

Followed by:

sudo apt-get autoremove

 

Installing Nginx on Ubuntu 15.10

To install Nginx, use the command:

sudo apt-get install nginx

Hit Enter, when it asks,”Do you want to continue?”

Start the Nginx service with the following command:

sudo service nginx start

Verify that NGINX is working by opening your browser and entering your IP address or hostname.

Don’t know your IP address? No problem, run the following command:

ifconfig

You will get an output similar to the one below. Next to eth0 we can see that the inet addr is 192.168.0.192. That is your IP address.

This is an example of ifconfig that shows the IP address of 192.168.0.192

This is an example of ifconfig that shows the IP address of 192.168.0.192

So in our browser we would go to http://192.168.0.192.

Once you have entered your IP address or Hostname, you should get a web page similar to the following.

This is an example of the default web page for NGINX on Ubuntu 15.10

This is an example of the default web page for NGINX on Ubuntu 15.10

Now that Nginx is installed, we can move on to installing MySQL.

Installing MySQL on Ubuntu 15.10

Install MySQL with the command:

sudo apt-get install mysql-server

Hit Enter, when it asks,”Do you want to continue?”

During the install, a screen similar to the one below will pop up. You need to create a MySQL root password. Choose a password of your choice, It should be a strong password.

Set a secure password for the MySQL root password

Set a secure password for the MySQL root password

Hit enter to continue. Once you have hit enter, a new screen will appear prompting you to re-enter the password you just picked.

Reenter your MySQL root password

Reenter your MySQL root password

MySQL is now installed, but we add some basic security by running the MySQL secure installation:

sudo mysql_secure_installation

It will first prompt you to enter your MySQL root password, which you can do so.  After it will ask you to “Change the root password?”, type N and then press Enter. The rest of the question you can hit Enter for the defaults unless there are certain things you would like to keep open.

This is an example of the MySQL secure installation

This is an example of the MySQL secure installation

Now that MySQL is installed, we can now install PHP.

Installing PHP on Ubuntu 15.10

Install PHP with the following command:

sudo apt-get install php5 php5-fpm php5-mysql

Hit Enter, when it asks, “Do you want to continue?”

To get Nginx to work with PHP correctly, we need to make changes to the Nginx configuration file. This guide we will be using a simple Nginx config file.

First, we are going to move the original configuration file to a new filename. Run the command:

sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

Next using a text editor of your choice, we are going to make a file called default in /etc/nginx/sites-available. For nano use the command:

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

Copy the following into your text editor:

server {
        listen       80;
        server_name  your_site_name.com;
        root /usr/share/nginx/html;
        index index.php index.html;

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

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
                root /var/www/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

In nano, to exit and save, hit Ctrl+x , Ytype , and then Enter.

Since we made changes to the configuration file, we need to restart Nginx, by running the command:

sudo service nginx restart

To test PHP, we are going to create a file called info.php.

Using a text editor of your choice, create info.php in /usr/share/nginx/html/.

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

Copy the following into your text editor.

<?php
phpinfo();
?>

In your browser, you can go to http://Your-Hostname/info.php or http://Your-IP-Address/info.php. As above, in this example, we would use http://192.168.0.192/info.php.

You should get a web page that shows the version of PHP among other things, it will look like the image below.

This is an example of the PHP.info page on Ubuntu 15.10

This is an example of the PHP.info page on Ubuntu 15.10

Now that we verified that the info.php is working, it is a good idea to remove it as it gives a potential attacker information that can be used to craft a particular attack against your server. To do that run the command:

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

Congratulations, you have installed LEMP on Ubuntu 15.10. Thank you for following this how-to. Please check back for more updates.