Cookie named '' is not set!

Install Nginx, MySQL, PHP v7 (LEMP) stack on CentOS 7


Nginx is a growing open-source web server software and PHP v7 is the latest version of PHP engine. In this tutorial, we will use it to build a LEMP (Linux, ENginx, MySQL, PHP) stack server. Nginx replaces the popular Apache package found in LAMP stack.

What you’ll need

Before you begin this guide you’ll need the following:

  • root access to the VPS

Step 1 — Installing Nginx on CentOS 7

Since Nginx is not available in default CentOS repositories, we will install EPEL repository by running this command:

Next, we will install Nginx itself:

After installation completes, enable Nginx start on boot and run it:

In order to check if Nginx is running, you can visit your IP address via the browser. Firstly, locate your IP:

Then, just copy-paste it into the browser and you should see similar page:

Nginx Default Page

Step 2 — Installing MySQL (MariaDB)

Once the web server is installed, we can proceed further towards MySQL installation. MariaDB is a community fork of the old and well known MySQL service. Since MariaDB comes with default CentOS repositories we can run Yum to install it:

After finishing the installation, enable and start the service:

Lastly, run initial setup script which will remove some of the default settings:

MariaDB will ask you for the root password, however, since this is initial installation, you don’t have any, so just press enter. Next prompt will ask if you want to set a root password, enter Yand follow the instructions:

You can safely click ENTER key and accept default settings for all other questions. After you complete the setup, proceed further to PHP installation.

Step 3 — Installing PHP v7.1.0

The first thing that we will do is install additional CentOS repo which contains required packages for PHP v7.1:

Enable php71 repository which is disabled by default:

Secondly, install PHP package:

Install common modules:

Step 4 — Configuring Nginx to work with PHP 7

Create a new Nginx configuration file by running vim or nano text editor:

Input this code:

IMPORTANT! Replace your_server_ip with your actual server IP.

Save the file by hitting CTRL + X (CMD + X for Mac users). Restart Nginx for change to take effect:

Now, open PHP-FPM configuration:

Find and replace these lines:

user = apache to user = nginx

group = apache to group = nginx

listen.owner = nobody to listen.owner = nginx = nobody to = nginx

And, lastly, under ;listen = add this line:

listen = /var/run/php-fpm/php-fpm.sock

Once again, save the file by hitting CTRL + X. And finally, start php-fpm and enable it on boot:

Leave a Reply

Your email address will not be published. Required fields are marked *