This will be a tutorial for setting up your own LEMP stack on Debian 7 Wheezy. This might be also used for installing one on Ubuntu but is not guaranteed.

LEMP Stack?

LEMP is almost the same with a LAMP stack but the Web server part is replaced with Nginx. LEMP is an acronym for a software bundle of Linux, Nginx(for E), MySQL and PHP. Sometimes any of this softwares gets replaced like MySQL can sometimes be replaced with MariaDB and PHP either Perl or Python.


I’ll assume that a Debian 7 Wheezy is already installed and ready to be configured for installing a LEMP stack. Login as a root in your terminal or you can use sudo.

Make Sure Everything Is Up To Date

Install MySQL

Install MySQL by typing

On process of installing MySQL it should ask you for the root password.

Install Nginx

Nginx will be our web server and to install it type in your terminal

After installing Nginx make sure that it is working correctly by going into your browser and browsing into “localhost”. An Nginx welcome page should appear if everything was installed without problem.

Install PHP

PHP will be our scripting language and to install it type in your terminal

php5 in the list is the scripting language itself and php5-fpm will be used for the communication between our webserver and the translation of the php scripts and php5-mysql is for enabling MySQL support for php5.

Setup php5-fpm With Nginx

Now that we have installed everything we need to setup php5-fpm to communicate with Nginx. Since Nginx is doesnt have something like libapache2-mod-php5 module for Apache we need the php5-fpm to run our php scripts and communicate with Nginx to respond every requests.

Prepare Nginx VirtualHost

To do so we need to edit the file in /etc/nginx/sites-enabled/default. Open the file with

Add index.php in the index directive

Find the line where the php config is commented out. It should look like below

Removed some of the comments on this section it should look like below

Save the file and exit.

Note: You can also change the server_namedirective. By default it is set to localhost but you can set it to your public IP or your domain name.

After editing the default VirtualHost file. Make sure the reload Nginx, so the change we did will be loaded.

Setup php-fpm

Since Nginx is expecting to communicate with php-fpm in a unix socket located in /var/run/php5-fpm.sock. Declared on this line

from the above VirtualHost. We will need to make sure that php5-fpm is also listening on this unix socket. To check open the file in /etc/php5/fpm/pool.d/www.conf

Look for the line with the listen directive and make sure it is set to listen on a unix socket located in /var/run/php5-fpm.sock. It should look like this

If it set to other value make sure to replace it with the above. Save the file and exit.

Make sure to reload the php5-fpm daemon

Test Out The LEMP Stack

Now that we have configured Nginx and php5-fpm we can test the LEMP stack if it is now working properly.

Create a file called php-info.php in the root directory. You can check where this is in the default VirtualHost file of Nginx. The directive is root and after the scace will be the location of the root directory. The location is usually in /usr/share/nginx/www. Create the file by

Put the code below into the file

Save and exit.

Now go into your browser and browse into “localhost” or whatever you put in the server_name directive and you should see the php informations if everything was installed successfully

Thats it! Now you have your LEMP stack all setup and ready.

Looking for cool VPS provider? Try Linode(referral link), they are currently my VPS provider.