In this tutorial we will cover the steps needed to install the LEMP stack on your CentOS 6.4, Debian or Ubuntu platform. LEMP is a combination of operating system and open-source software which will help you set up a working hosting environment. The acronym LEMP is derived from the first letters of Linux, nginx (Engine X), MySQL and PHP.

Requirements:

  • CentOS 6.4, Debian or Ubuntu installed on your computer/server
  • SSH access (Command line access to the server)
  • root privileges

Install Nginx

Nginx (pronounced "engine-x") is one of the most popular open source web servers for high-traffic websites. It can be used either as stand-alone HTTP server or configured as reverse proxy server and load balancer.

Due to the fact that some of the packages might not be available by default you will need first to add additional repositories to your Linux platform. This can be done with the following commands:

CentOS 6.4

Debian:

For the nginx installation we will use the default package manager included inside the corresponding Linux distribution::

CentOS 6.4

Ubuntu/Debian

Install the nginx package and all of its dependencies.

Next, you need to disable ipv6 as it is currently not supported and then start Nginx:

Test the functionality of the Nginx service

Once the installation is completed you can test the nginx service using your browser:

http://localhost/ or http://X.X.X.X

where X.X.X.X is your server's IP address, i.e. http://1.2.3.4/

You should be able to see the default nginx page inside your browser.

An easy way to find your server's IP address is to execute the following command:

Install MySQL

MySQL is one of the most popular database management systems. The installation of the software can be completed with the following commands:

CentOS 6.4

Ubuntu/Debian

During the installation you might be prompted to set root password for the MySQL service. If not, you can set the root password after completion of the installation using the following command:

Test the functionality of the MySQL service

You can check if everything went well during the installation using the default MySQL client:

You will be prompted to enter the root password.

Install PHP

PHP is one of the most used open-source scripting languages preferred by the web developers. The software installation can be completed with the following commands:

CentOS 6.4

Debian

Ubuntu

Configure PHP to work correctly with nginx

In order for the services to be running correctly minor PHP re-configuration should be made to the nginx and php-fpm configuration files:

CentOS 6.4:

Open the php-fpm configuration file:

edit the listen value the following way:

After that open the nginx configuration file:

uncomment the lines and set the following syntax for them:

Make sure that /var/run/php5-fpm.sock has correct permissions:

After that restart both services:

Debian:

Open the php-fpm configuration file:

edit the listen value the following way:

After that open the nginx configuration file:

and set the following syntax for the provided lines:

Make sure that /var/run/php5-fpm.sock has correct permissions:

After that restart both services:

Ubuntu:
Open the php-fpm configuration file:

and set the listen value to:

After that open the nginx configuration file:

and set the following syntax for the provided lines:

After that restart both services:

Test the functionality of the PHP parser

Once completed you can test the functionality of the service by creating a test PHP info file inside the nginx web root folder (it might be /usr/share/nginx/www or /var/www/):

containing the following lines:

Save the file and open it using your browser:

Default PHP information page should be displayed on your end.

Start Up nginx/MySQL/PHP automatically on server boot

In order for the services to start automatically upon server boot up you can execute the following commands:

CentOS 6.4

Ubuntu/Debain:

At the end you should have a working hosting environment which includes the nginx, MySQL and PHP software.