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 through the step by step installation of LEMP Stack on the CentOS 8 server.
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 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:
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:
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:
<?php phpinfo(); ?>
Save and close the file. If you installed 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.
Congratulations! You have successfully install LEMP. Thanks for using this tutorial to install LEMP Stack on CentOS 8 system. For additional help or useful information, we recommend you to check the official LEMP website.