CentOSLinuxTutorials

How To Install LEMP Stack on CentOS 8

Install LEMP Stack on CentOS 8

In this tutorial, we will show you how to install LEMP Stack on CentOS 8. For those of you who didn’t know, LEMP stands for Linux, Nginx (pronounced engine X), MariaDB/MySQL, and PHP, all of which are open source. It is the most common software stack that powers dynamic websites and web applications. Linux is the operating system; Nginx is the webserver; MariaDB/MySQL is the database server and PHP is the server-side scripting language responsible for generating dynamic web pages.

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 and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of LEMP Stack on the CentOS 8 server.

Prerequisites

  • A server running one of the following operating systems: CentOS 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install LEMP Stack on CentOS 8

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo dnf update

Step 2. Installing Nginx on CentOS 8.

Nginx is a high-performance web server and is very popular these days, The first step is to install Nginx. So open a terminal session or connect to your server using SSH:

sudo dnf install nginx

Once the installation is done, start and enable Nginx to run on system boot:

systemctl enable --now nginx

The next step is to open the ports in the Firewall so that we can use Nginx:

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

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:

Install LEMP Stack on CentOS 8

Step 3. Installing MariaDB Database Server.

MariaDB is a pretty good database manager. It is a MySQL fork and therefore compatible with it. It is one of the open-source values. Install MariaDB on CentOS 8 with the command:

sudo dnf install mariadb-server

Once you have installed the MariaDB server, start and enable it to run on system boot:

systemctl enable --now  mariadb

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL:

mysql_secure_installation

Step 4. Installing PHP on CentOS 8.

Install PHP and related modules using the following command:

sudo dnf install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring

If you need other PHP extensions for your web applications, simply install by running:

sudo dnf install php-EXTENSION

### Replacing EXTENSION with your respective PHP module ###

Then, start and enable PHP-FPM to run on boot:

systemctl enable --now php-fpm

Step 5. Testing PHP on CentOS 8.

You can test PHP to confirm that is working as required as well as check the version and installed modules using the simple PHP info script:

nano /usr/share/nginx/html/test.php
<?php phpinfo(); ?>

Save and close the file. If you installed the LEMP stack on CentOS 8 server, type in 127.0.0.1/info.php or localhost/info.php in the browser address bar. You should see your server’s PHP information. This means PHP scripts can run properly with the Nginx web server.

Install LEMP Stack on CentOS 8

Congratulations! You have successfully installed LEMP. Thanks for using this tutorial to install LEMP Stack on CentOS 8 system. For additional help or useful information, we recommend you check the official LEMP website.

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 the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button