How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6.7

This howto guide explains more deeply on how to install LEMP (Linux, Nginx, MySQL, PHP) on pre-installed Linux servers and installation instructions can be used on CentOS 6.7 servers using Remi and Nginx repositories with YUM command.

In this guide we use latest MySQL 5.5.49, PHP 5.6.21 and Nginx/1.10.0 versions with PHP-FPM modules with Nginx. So, before moving further for installation let’s discuss about Nginx and PHP-FPM.


What is Nginx?

Nginx (Engine X) is open source robust light and high performance Web server, reverse proxy sever and also mail proxy server for HTTP, SMTP, POP3 and IMAP protocols. To know more about features visit


What is PHP-FPM?

PHP-FPM stands for FastCGI Process Manager is an alternative PHP FastCGI implementation with some additional useful features for heavily loaded websites. For more information visit


Step 1: Installing Remi Repository


Step 2: Installing Nginx Repository

Create file /etc/yum.repos.d/nginx.repo and add following content to repo file:


Step 3: Installing Ngnix 1.10.0, MySQL 5.5.49, PHP 5.6.21 & PHP-FPM

Install NGINX with the following command:

Start the NGINX service with the following command:

Configure NGINX to start when the system is rebooted:

You will now have NGINX installed on your server. This can be verified by typing in the following with your IP ADDRESS on your browser. Also, all configuration files are provided on the page.

We can now verify NGINX is working by opening your browser and entering the URL http://your-server's-address. you should get a blue Nginx test page.

How To Set Up nginx Virtual Hosts


Install MySQL with the following command to begin the install:

Start the service with the following command:

You can do some configuration of MySQL with this command:

The prompt will ask you for your current root password.

Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.

Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.

CentOS automates the process of setting up MySQL, asking you a series of yes or no questions.

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the changes.

Configure MySQL to start when the system is rebooted:


Installing and Configuring php-fpm on CentOS 6.7 for LEMP

Install php-fpm with the following command:

PHP Modules
PHP also has a variety of useful libraries and modules that you can add onto your server. You can see the libraries that are available by typing:

Terminal then will display the list of possible modules. The beginning looks like this:

To see more details about what each module does, type the following command into terminal, replacing the name of the module with whatever library you want to learn about.

Once you decide to install the module, type:

Start the php-fpm service with the following command:

Make sure php-fpm starts on boot with the following command:


Configure php

Using your favorite editor, edit the file /etc/php.ini and change the default timezone. It should look similar to the block below.

And find the line, cgi.fix_pathinfo=1, and change the 1 to 0.

If this number is kept as a 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process the exact file path—a much safer alternative. Save and Exit.


Using your favorite editor, edit the file /etc/php-fpm.d/www.conf and change user and group from apache to nginx. It should look similar to the block below.

Finish by restarting php-fpm.

Now we need to make some changes to the Nginx configuration file so that php-fpm works correctly with Nginx. Using your favorite editor, edit the file /etc/nginx/conf.d/default.conf and carry out the following changes or copy the following block below into your conf file.

1) Add the index.php to the index location

2) Change the root location to /usr/share/nginx/html

3) Uncomment the Pass PHP scripts to FastCGI section.

4) Change the fastcgi_param SCRIPT_FILENAME to use /usr/share/nginx/html$fastcgi_script_name

Create a test PHP file in the following directory with the following command:

Add in the following line:

Then Save and Exit.

Restart nginx so that all of the changes take effect:

Test your page in your browser with the following hyperlink changed with yourIP address:


Congratulations! You have just installed LEMP on your CentOS 6.7 Server. Thank you for following along in this How-To! Check back with us for any new updates.

How To Set Up nginx Virtual Hosts

Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks



  3. atlantic-community