How To Install LEMP on CentOS 7

Install LEMP on CentOS 7

For those of you who didn’t know, A LEMP software stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym that represents the Linux operating system, with the Nginx webserver (which replaces the Apache component of a LAMP stack). The site data is stored in a MySQL database (using MariaDB), and dynamic content is processed by PHP.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation of LEMP (Linux, Nginx, MariaDB, and PHP) on the CentOS 7 server.

Install LEMP on CentOS 7

Step 1. First of all, make sure that all packages are up to date.

Step 2. Installing and Configuring NGINX in CentOS 7.

Nginx is not yet available in CentOS 7 official repositories, so we have to add/install Nginx yum repository by issuing the command below:

Start Nginx and add it to automatically start on your system start-up using:

You can verify that Nginx is really running by opening your favorite web browser and entering the URL http://your-server’s-address, if it is installed, then you will see this:

Install LEMP on CentOS 7
Nginx Default Page

Step 3. Configure the Nginx web server.

Let’s say you have a domain and you like to use it to host a PHP based web application in /var/www/ like WordPress, Joomla. To set-up Nginx serve requests for, and serve the PHP scripts in /var/www/ you would have to create a server block in /etc/nginx/conf.d/ which would look something like:

Test and re-start Nginx using:

Step 4. Installing and Configuring PHP on CentOS 7.

Install PHP on CentOS 7 with the following command to begin the install:

You may want to install some other PHP extensions required by your applications. The following is a list of the available PHP modules:

Restart Nginx so all the changes take effect:

To test PHP, create a test file named info.php with the content below. Save the file, then browse to it to see if PHP is working:

Step 5. Installing and Configuring MariaDB on CentOS 7.

Install MariaDB with the following command to begin the install:

After that add it to your system startup and start the MariaDB server using the following commands:

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL:

To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MySQL database):

Step 6. Configure IPTables or firewalls.

Congratulations! You have successfully installed the LEMP stack. Thanks for using this tutorial for installing LEMP (Linux Nginx, MariaDB, and PHP) in CentOS 7 system. For additional help or useful information, we recommend you to check the official Nginx, MariaDB, and PHP web site.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!