LEMP is a term used for a group of open source software that is installed to enable servers for hosting dynamic websites and web apps. The term LEMP is actually an acronym which refers to Linux, Enginx, MySQL and PHP. Let’s take a look at how to get your LEMP stack installed on a VPS server setup in CentOS 7.

Requirements:

Before you go ahead with this guide make use that you have a separate account on your server without root privileges. You can easily break down this guide into four key steps to enable better understanding of the installation process. Before proceeding make sure that your SELinux context in your Nginx config files is correct or, you can change the SELinux mode to permissive or disabled.

Step 1 – Installing NginxNginx

 

  • Nginx is responsible for allowing web pages to be displayed. Nginx works as a web server and you need to manually open the CentOS 7 EPEL repository in your terminal using sudo commands. All of your operations can be easily executed without needing any kind of root privileges. It will allow you to install the Nginx repository onto your own VPS server and you need to now do with installing Nginx to set up your web server.
  • One you fire up the Nginx web server on your virtual private server you will be able to spot check if everything is working as it should be. If you performed the above steps correctly you should be able to use the public IP address of your private server.
  • You need to visit the Nginx web page to make sure everything is working properly. Your web server should now be correctly installed to your system. Before you do with the next steps you need to enable Nginx to start at boot.
  • Once you are done with the above steps you need to find your server’s IP address. You can either choose to use a SSH connection to find it or you can use the iproute command line.

Note: You might be presented with two lines of data, both of them are correct ip addresses but it’s likely that you will be able to use only one of them. This marks the end of the steps required to install Nginx.

Step 2 – Installing MySQL

installing mysql

Instead of using MySQL you should opt in for installing MariaDB instead which is a replacement to MySQL. It is a community developed project and will allow you to install a DBMS system into your private virtual server. Having MariaDB or MySQL setup on your server will allow you to store and manage information on your virtual private server very easily. You need to install MariaDB/MySQL in the same way you installed the Nginx app. But apart from the main app you also need the helper packages to help the different components communicate. Once you are done you need to start the app and setup your database.

setup database

  • Once you have installed the SQL database you need to install a simple security strict to remove any kind of dangerous defaults that might exist in the system. It also locks down access to some of the features for added security of your data.
  • When you are asked for the password for root leave it blank as you do not have a set password, pressing enter will take you to the next menu. If you want to set a root password you can press the password and hit Y to confirm.
  • Whenever you want to stick to the default values you can simply hit enter when you reach any prompt screen. You also need to set the MariaDB/MySQL to start on boot using a ‘sudo systemctl enable’ command.

This completes the setup of your database and we can move on to installing our PHP.

Step 3 – Installing PHP

installing php

PHP is the most crucial part among the three and it allows our VPS system to process data and display content dynamically. You can use the part to run several scripts connect to your database and present the information on your web server that you just installed. Once you install these components you will be able to access PHP-MySQL and PHP-FPM packages as well.

  • First, you need to configure the PHP processor to make it work with the other components. There are some configurations changes that you need to make to make sure your setup is secure and it involves opening the main php file with root privileges.
  • php infoLook for a cgi.fix_pathinfo file with is commented out with a semicolon and has a value of 1 set by default making it highly insecure. It’s a very insecure setting that needs to be changed else your PHP files may malfunction and other users will be able to spam PHP requests which will get executed that should not be executed under normal circumstances. Change the value to 0 to make sure you remove this security flaw.
  • Now we need to start our PHP processor using sudo commands and enable the PHP-FPM to start on boot.

Step 4 – Configuring Nginx for PHP Page processing

We now have all the required components set up and the only configuration change that you need to do is make sure Ngifx uses your custom PHP processor that you installed for displaying any kind of dynamic content.

  • Fire up the Ngifx app on a server level and you need to reach the server block configuration on the Ngifx app. You need to add an index.php option to the file and allow the Ngifx app to index all PHP files every time a new directory is requested.
  • Now you need to change the name of the server so it matches that of your server’s domain address. You should also change the server name to match that of your public IP address or your domain name to make it easier to find and access.

Restart Ngifx to make all the necessary changes. This concludes the steps involved in setting up LEMP on your system and now you need to run a simple PHP script to make sure the VPS is working as intended. If you find any problems you should recheck with the above steps and try again.

99 Shares
+1
Tweet
Share12
Pin85
Share2