In this article, we’ll explain how to install LEMP stack on AlmaLinux 8.
The LEMP software stack is a group of software that can be used to serve dynamic web pages and web applications written in PHP. This is an acronym that describes a Linux operating system, with an Nginx (pronounced like “Engine-X”) web server. The backend data is stored in the MySQL database and the dynamic processing is handled by PHP.
This article will guide you with the installation of Nginx as a web server, MariaDB as a database and PHP.
- A AlmaLinux installed dedicated server or KVM VPS.
- A root user access or normal user with administrative privileges.
Install LEMP Stack on AlmaLinux 8
1. Install Nginx Web Server
Install NGINX using following command:
# dnf install nginx -y
After the installation is finished, run the following commands to enable and start the server:
# systemctl start nginx && systemctl enable nginx
Configure firewall. Add http and https ports in firwall using following command:
# firewall-cmd --permanent --add-service=http
# firewall-cmd --permanent --add-service=https
To apply the changes, you’ll need to reload the firewall service:
# firewall-cmd --reload
2. Install MariaDB Database
Open the setting MariaDB repositories page, choose a distro, release and version of the MariaDB you wish to install.
In this article, we are using MariaDB 10.5
Create the MariaDB.repo file in you favourite editor:
# vi /etc/yum.repos.d/MariaDB.repo
And add following lines:
# MariaDB 10.5 CentOS repository list
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
save and exit.
Now, update the repository.
# dnf update -y
Now, start the installation of the MariaDB 10.5
# dnf install mariadb-server -y
After it’s finished, start MariaDB:
# systemctl start mariadb.service && systemctl enable mariadb.service
The installation is completed.
Secure the MySQL
To secure the MySQL installation, you should remove the anonymous user created during installation. To do so, run the following command:
Initially, there is no password for root. Press ENTER.
Enter current password for root (enter for none):
Press ENTER to enter a new password.
Set root password? [Y/n]
Enter and confirm a root password for MariaDB.
Re-enter new password:
Password updated successfully!
Press ENTER to remove the anonymous user.
Remove anonymous users? [Y/n]: Y
Press ENTER to disallow remote root logins.
Disallow root login remotely? [Y/n]: Y
Press ENTER to remove the test database.
Remove test database and access to it? [Y/n]: Y
Press ENTER to reload the privilege tables.
Reload privilege tables now? [Y/n]: Y
This completes the basic security configuration.
3. Install PHP
Add EPEL(Extra Packages for Enterprise Linux) repository:
# dnf install epel-release -y
Install Remi repository:
# dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Here you can choose which PHP version you want to install.
# dnf module list php
Remi’s Modular repository for Enterprise Linux 8 - x86_64 316 kB/s | 746 kB 00:02
Safe Remi’s RPM repository for Enterprise Linux 8 - x86_64 681 kB/s | 1.7 MB 00:02
AlmaLinux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
Remi’s Modular repository for Enterprise Linux 8 - x86_64
Name Stream Profiles Summary
php remi-7.2 common [d], devel, minimal PHP scripting language
php remi-7.3 common [d], devel, minimal PHP scripting language
php remi-7.4 common [d], devel, minimal PHP scripting language
php remi-8.0 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
Next, in order to enable the PHP remi-8.0 stream run the following dnf commands.
# dnf module reset php -y
# dnf module enable php:remi-8.0 -y
Now, install PHP. Here you can choose or add PHP modules as per your requirements.
# dnf install php php-fpm -y
Verify the installation.
# php -v
The installation process has been completed successfully.
Navigate to your browser and enter your server ip.
In this article, we have explained how to install LEMP stack on AlmaLinux 8.