LEMP is the acronym used to describe a specific open source software configuration for Linux web servers.
L – Linux (In this case, Debian 8)
E – Nginx (Pronounced Engine X)
M – MySQL
P – PHP
This tutorial will walk you through how to install nginx, mysql and php-fpm, on your Debian 8 server.
This article will also assume that you are not running these command as Super User, because it is not good practice,
however if you are, simply remove ‘sudo’ from the commands shown below.
We will be using the apt-get package manager to install all of the software packages required for this configuration. Before we begin, it is important to update your package manage, so that it installs the most up to date packages. The following command will do this for you.
Installation of MySQL
MySQL is an open source database, which is used for storing and retrieving data using SQL (Structured Query Language).
As most web pages now load their content dynamically, a database is a vital part of any web application.
The following command will install MySQL to your server.
As with any apt-get install command, you will be alerted of the disk space that this install requires.
Press Y to continue.
During the installation, you will ask to set the root password for your MySQL database. If you pressed Enter before entering anything, the password will be set to “” (an empty string). This is not a problem, you will be able to set it to something secure in later steps.
After installation completes, we need to create system tables in our database, using the following command.
Now that these system tables have been created, you can start running the secure installation processes.
As the script starts, you will be asked for the MySQL root password. if you did not set one, just press Enter
You will be asked whether you want to change the root password. Press Y and set one if you have not already. If you have already set a password and want to keep it, just press N.
You will now be asked the following questions:
Remove anonymous users?
Disallow root login remotely?
Remove test database and access to it?
Reload privilege table now?
The type of environment that this database is for (Development or Production) will determine the answer for these questions.
For a development environment, you may want to leave the anonymous user and allow root to login remotely for ease of access
If you are new to MySQL and want some test data, you may want to keep the test database.
If you are using this for a production environment, the answer for all of these questions should be yes.
Installation of Nginx
Nginx is a web server that can be used as an alternative, or in parallel to Apache.
The perks of Nginx is that it is very responsive under heavy load, due to its asynchronous event-driven architecture, it is efficient with resources, and is faster than Apache when responding to static page requests.
The downfall to Nginx is that it does not offer native support for rendering dynamic content, unlike Apache.
To install Nginx, run the following command.
After the installation completes, you need to start the service.
You can verify that the service has started, by opening a web browser, and navigating to your server IP address.
If the services is running, you should see the ‘Welcome to Nginx on Debian!’ splash page.
Now we need to configure Nginx
Make to following changes to your configuration file, filling in server_name and domain with your own data.
If you don’t have this information at the moment, you can always add it alter.
Save the file and restart the Nginx service.
With this configuration, your web browser will no longer show the default splash page.
It is now looking for a webpage called index in /usr/share/nginx/www
This will return a 404 error until you create this page.
Installation of PHP
PHP is a hypertext preprocessor. This means that the PHP pages are rendered on the server, rather than on the client that is requesting them.
Let’s go ahead and install php-fpm.
Now lets open the php.ini file so that we can make some changes.
Search this file for the following line:
and change it to:
This is to ensure that the php interpreter processes only the exact file path.
Once you are done with the changes, restart the php-fpm to ensure that the changes take effect.
PHP Info Page
Now that we have finished installing and configuring everything in our LEMP stack, we can create a file that will show detailed information of the configuration. This file should only be used for development, and should not be kept in a production environment.
To make this file, run the following command.
Insert the code below into the file and save it.
To view your phpinfo page, open your browser and go to, SERVER_IP/info.php.
You have now successfully installed a LEMP stack on your server.