How To Set Up LEMP Stack On CentOS 8

In this guide, we’ll set up LEMP Stack on CentOS 8. The LEMP stack is a collection of software commonly employed for running dynamic web applications.

 It is an acronym representing Linux, Nginx, MySQL, and PHP. Here is why some consider it:

  • Linux is an open-source operating system widely adopted by servers worldwide, recognized for its stability, security, and performance.
  • Nginx serves as a speedy and efficient web server. Often utilized as a reverse proxy, it can handle static requests like images and CSS files, allowing the primary web server to focus on dynamic requests requiring PHP processing.
  • MySQL is a relational database management system (RDBMS) responsible for storing and managing data for web applications, renowned as one of the most popular RDBMS options globally.
  • PHP is a server-side scripting language for creating dynamic web pages, ranking among the most widely used scripting languages.
  • The LEMP stack is a favored choice for running dynamic web applications due to its reliability, scalability, and security. It is also relatively straightforward to set up and maintain.

Seven advantages of utilizing the LEMP Stack On CentOS 8:

  1. Performance: Nginx serves as a rapid web server, enhancing the performance of web applications.
  2. Scalability: The LEMP stack is scalable, enabling the easy addition of more servers as traffic increases.
  3. Security: The LEMP stack provides a secure environment, safeguarding web applications against potential attacks.
  4. Ease of use: Even for beginners, the LEMP stack is relatively user-friendly in setup and maintenance.
  5. Scalability: The LEMP stack is highly scalable, allowing you to handle increasing traffic and growing user demands.
  6. Security: The LEMP stack incorporates security features and best practices to protect your web applications. 
  7. Ease of Use and Maintenance: There are numerous resources, tutorials, and a supportive community available to assist with installation, configuration, and ongoing maintenance.

The LEMP stack is worth considering if you seek a dependable, scalable, secure platform for dynamic web applications.

Let’s set up the LEMP stack on CentOS 8

The first step is to update your system. It facilitates the smooth installation of different packages. Use the following code:

  • sudo dnf update

1. Let’s install Nginx

We will utilize Nginx, a high-performance web server, to serve web pages to visitors. We will install this software using the dnf package manager, the default package manager on CentOS 8.

Run this code on the terminal:

  • sudo dnf install nginx

Start, enable, and configure the firewall by

  • sudo systemctl start nginx
  • sudo systemctl enable nginx

Configuring firewall by:

  • sudo firewall-cmd –zone=public –permanent –add-service=http
  • sudo firewall-cmd –zone=public –permanent –add-service=https
  • sudo firewall-cmd –reload

Now your web server is ready, let’s proceed to MySQL.

2. Install MySQL 

It will act as our database server to help manage records and databases. Run the following command:

  • sudo dnf install @mysql

Once it’s done, we have to start it and check the status by

  • sudo systemctl start mysqld
  • sudo systemctl enable mysqld

Let’s then secure it

  • sudo mysql_secure_installation

Follow the prompts given and ensure your database is secure.

3. PHP comes next

Complete the setup by installing the PHP programming language and the necessary modules for PhpMyAdmin.

Done by;

  • sudo dnf install php php-mysqlnd

Now, you must restart Nginx and PHP-FPM to apply the changes.

  • sudo systemctl restart nginx
  • sudo systemctl restart php-fpm

4. Finally, test your set-up

Create a PHP info file to test if your LEMP stack works correctly. Use the following command to create the file:

  • sudo nano /usr/share/nginx/html/info.php

In the opened text editor, enter the following line:

  • <?php phpinfo(); ?>

Save and Exit. Open your web browser and navigate to your server’s IP address or domain name, followed by “/info.php.” 

For example, if your server’s IP address is 192.168.0.1, enter “http://192.168.0.1/info.php” in the browser’s address bar.

You should see a page displaying PHP configuration details if everything is set up correctly. For security reasons, it’s recommended to remove the PHP info file. 

Run the following command to delete it:

  • sudo rm /usr/share/nginx/html/info.php

Congratulations! You have successfully set up the LEMP stack on CentOS 8. You can now start developing and hosting dynamic websites and applications.

Remember to secure your applications and regularly update your software to maintain a secure and reliable environment.

Difference between the LEMP stack and the LAMP stack:

FeatureLEMP stackLAMP stack
Web serverNginxApache
DatabaseMySQLMySQL, MariaDB, PostgreSQL
Scripting languagePHPPHP, Python, Ruby

Ultimately, selecting the most appropriate stack hinges on your specific requirements and preferences.

Nginx is an excellent choice for prioritizing a fast and reliable web server. Opting for Apache makes sense if you already possess familiarity with it. 

Likewise, the desired database or scripting language support may guide your stack choice. Considerations When deciding between the LEMP stack and the LAMP stack, consider the following:

  • Performance: The LEMP stack with Nginx as the web server is preferable for optimal speed. Nginx’s impressive performance can enhance your web application’s responsiveness.
  • Scalability: Both stacks offer scalability; however, the LEMP stack might be better suited for handling substantial traffic loads.
  • Security: Both stacks prioritize security, but the LEMP stack may be more appealing if security is a top concern. Nginx boasts robust security features to safeguard your web applications.
  • Ease of Use: Both stacks are relatively easy to set up and maintain. However, the LEMP stack could benefit beginners with its more straightforward configuration and smaller footprint.

If you need help deciding which stack to choose, you can experiment with both options to determine the better fit. 

Numerous online tutorials are available to guide you in getting started with either stack.

Wrapping up;

Now you’ve installed the LEMP stack on CentOS 8! Ultimately, the ideal stack choice depends on your specific requirements and preferences. 

Nginx is suitable for prioritizing a fast and reliable web server. If you are already familiar with Apache, it may be preferable. 

If you require a specific database or scripting language, select the stack that supports your requirements.

Was this article helpful?

Related Articles

Leave A Comment?