How to Install LEMP Stack on CentOS 8

Install LEMP Stack on CentOS 8

In this article, we will have explained the necessary steps to install and configure LEMP Stack on CentOS 8. 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 a variation of the ubiquitous LAMP stack used for developing and deploying web applications. Traditionally, LAMP consists of Linux, Apache, MySQL, and PHP. Due to its modular nature, the components can easily be swapped out. With LEMP, Apache is replaced with the lightweight yet powerful Nginx.

Install LEMP Stack on CentOS

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

Step 2. Installing Nginx.

Starting with CentOS 8, the Nginx package is available in the default CentOS repositories. Installing Nginx on CentOS 8 is as simple using following command:

Once the installation is complete, enable and start the Nginx service with:

To verify that the service is running, check its status:

The next step is to open the ports in the Firewall:

Step 3. Installing MariaDB.

Run the following command as root or user with sudo privileges to install MariaDB on CentOS 8:

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

MariaDB server package comes with a script called mysql_secure_installation performs several security-related operations, and sets the root password:

Step 4. Installing PHP.

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

The default PHP module is set to PHP 7.3. To install a newer PHP release, enable the appropriate version:

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

PHP uses FPM is installed as a dependency and used as FastCGI server. Start the FPM service and enable it to automatically start on boot:

Now, open PHP-FPM configuration:

Find and replace these lines:

Step 5. Set up Nginx configuration file.

Create directory inside var/www/html named idroot.us (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 idroot.us.conf (you can use your domain name). Then enter following code inside that file by replacing idroot.us 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 8. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.