How to Install LEMP Stack on CentOS 7

Install LEMP Stack on CentOS 7

In this article, we will have explained the necessary steps to install and configure LEMP Stack on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

LEMP is an acronym for Linux, Nginx, MySQL, and PHP. LEMP stack just like LAMP stack (with Apache instead of Nginx) is used for development and deployment of web applications. Nginx in LEMP provides a modular event-driven architecture handling requests using asynchronous events. This feature enables it to have high performance under high loads. The MySQL is used to store the website’s data whereas PHP is for processing the dynamic content of the sites.

Install LEMP Stack on CentOS 7

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Installing Nginx.

Now that the repository is added, it’s time to install Nginx:

Once it is installed, start and enable the Nginx service by typing:

Step 3. Installing MariaDB.

To install MariaDB type following command:

Once MariaDB server is installed, start and enable the service with:

Step 4. Installing PHP.

Add remi repository in CentOS so we can install latest PHP 7.2, typing following command:

Now enable PHP72 package using below command:

Then, that we have Remi repository enabled, we can install PHP FPM and several most common PHP modules with:

Now, open PHP-FPM configuration:

Find and replace these lines:

Step 5. Set up Nginx configuration file.

Create directory inside var/www/html named (you can use your domain name):

Configuration files for the website are stored inside /etc/nginx/conf.d directory so you need to create configuration file inside this directory named (you can use your domain name). Then enter following code inside that file by replacing with your domain name:

Do not forget to restart the Nginx service for the changes to take effect:

That’s all you need to do to Install LEMP Stack on CentOS 7. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.