How To Install LEMP on CentOS 7

r00t July 13, 2015

LEMP-linux

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 which represents the Linux operating system, with the Nginx web server (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 LEMP (Linux, Nginx, MariaDB and PHP) on 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 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:

Nginx Default Page

Nginx Default Page

Step 3 Configure Nginx web server.

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

Test and re-start Nginx using:

Step 4. Installing and Configuring PHP on CentOS 7.

Install PHP on the 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 he 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 steps carefully which will set 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 Firewall.

Congratulation’s! You have successfully installed 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 a best deal!
Share on Google+3Share on Facebook0Tweet about this on TwitterShare on Tumblr0Share on StumbleUpon5Share on Reddit0Pin on Pinterest3
The Tags:

Leave a Comment