How To Install Linux, Nginx, MariaDB, Php (LEMP) Stack

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

In this guide we use latest MariaDB, PHP and Nginx 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




Then type this command:



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



Install NGINX

with the following command:

Start the NGINX service with the following command:

Configure NGINX to start when the system is rebooted:

verify if nginx is running or not

Or You can confirm that nginx has installed on your VPS by directing your browser to your IP address.

You can run the following command to reveal your server’s IP address.

On the page, you will see the words, “Welcome to nginx”

Congratulations! You have now installed nginx.


Install MariaDB

Create a new MariaDB repository file /etc/yum.repos.d/mariadb.repo with nano:

And paste the following text

Then exit and save the file by pressing Ctrl+X, then Y.

As you see in the above example, it includes a gpgkey line to automatically fetch the GPG key that MariaDB uses to sign the repositories. This key is needed to verify the integrity of the package downloads.

Note: To find which repo you should use with the MariaDB repository generator.

For a standard server installation, you will need to download and install at least the client, shared, and server RPM files.

When the installation process is completed, you can start MariaDB. Please note that the MariaDB service is named “mysql”, so the command below is not a typo.

Run this command to start MariaDB on every boot.

You can check the version of the MariaDB installation with the following command:

So far so good!

You can do some configuration of MariaDB with this command:

The prompt will ask you for your current root password.

Since you just installed MariaDB, 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 MariaDB, asking you a series of yes or no questions.

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

Now, you have to restart MariaDB.


Install PHP and PHP-FPM

Run 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.

Save and Exit.

Finish by restarting php-fpm.


NOTE: If you want change listen = to /var/run/php5-fpm.sock. do it this step.

Edit the file /etc/php-fpm.d/www.conf and Find the line, listen =, and change the to /var/run/php5-fpm.sock.

Save and Exit.

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 copy the following block below into your conf file.



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

Add in the following line:

Then Save and Exit.

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

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


LEMP Configuration for High Traffic WordPress on Small VPS

Hosting WordPress Yourself



  3. atlantic-community