In this tutorial, we will show you how to install LEMP Stack on AlmaLinux 8. For those of you who didn’t know, LEMP is a combination of free, open-source software. The acronym LEMP refers to the first letters of Linux (Operating system), Nginx Server, MySQL (database software), and PHP principal components to build a viable general-purpose webserver.
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 the LEMP Stack on an AlmaLinux 8.
- A server running one of the following operating systems: AlmaLinux 8, CentOS, and Rocky Linux 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).
non-root sudo useror 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 AlmaLinux 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf update sudo dnf install epel-release
Step 2. Installing Nginx on AlmaLinux 8.
Now we run the following command to install the Nginx webserver:
sudo dnf install nginx
Once it is installed, you can start and enable the Nginx service using the following command:
sudo systemctl start nginx sudo systemctl enable nginx
Check the Nginx version:
Next, verify that the webserver is running and accessible by accessing your server’s IP address:
Step 3. Installing MariaDB on AlmaLinux 8.
MariaDB is a popular database server. The installation is simple and requires just a few steps as shown:
sudo dnf install mariadb-server mariadb
Once the installation is complete, start to enable it to start on system start-up using:
sudo systemctl restart mariadb sudo systemctl status mariadb sudo systemctl enable 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 MariaDB:
Configure it like this:
- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y
To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MariaDB database):
mysql -u root -p
Step 4. Installing PHP on AlmaLinux 8.
To Install PHP-FPM by running the following command:
sudo dnf install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring
Once the installation is complete, start and enable
php-fpm to start on boot with the below commands:
sudo systemctl start php-fpm sudo systemctl enable php-fpm
By default, PHP-FPM runs as the apache user. Since we are using an Nginx web server, we need to change the following line:
$ nano /etc/php-fpm.d/www.conf user = apache group = apache
Change them to:
user = nginx group = nginx
Save the file and restart both Nginx and PHP-FPM for the changes to come into effect:
sudo systemctl restart nginx sudo systemctl restart php-fpm
To test the PHP installation, creating an
info.php file in the
sudo nano /usr/share/nginx/html/info.php
Append the following lines and save the file:
<?php phpinfo(); ?>
That’s it, now you can access it using your server IP:
Step 5. Configure Firewall.
Now we add HTTP and HTTPS ports to the firewall using the following command:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload
Congratulations! You have successfully installed LEMP. Thanks for using this tutorial for installing LEMP (Nginx, MariaDB, and PHP) Stack on your AlmaLinux 8 system. For additional help or useful information, we recommend you check the official LEMP website.