How to Install LAMP Stack on AlmaLinux 8.5

How to Install LAMP Stack on AlmaLinux 8.5

LAMP is a popular open-source software stack that is mostly used for testing and hosting web applications. It’s an acronym for Linux Apache MariaDB / MySQL and PHP.

Apache is a popular open-source and widely used web server. MariaDB is a free and open-source, commercially supported relational database management system, and PHP is a server-side scripting language used for developing dynamic web pages.

In this tutorial, we will show you how to install LAMP stack on AlmaLinux 8.

Update Operating System

Update your AlmaLinux 8 operating system to make sure all existing packages are up to date:

$ sudo dnf update

Install Apache webserver

Well, like most of the Linux operating systems, we don’t have to add any third-party Repos to install Apache- HTTPd server.

You can install Apache via dnf package manager by executing the following command.

$ sudo dnf install httpd

Apache does not start automatically when it is installed. You can start the Apache service and configure it to run on startup by entering the following commands:

$ sudo systemctl start httpd
$ sudo systemctl enable httpd

Verify the status of the Apache service using systemctl status command:

$ sudo systemctl status httpd

Output:

 httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running)
Docs: man:httpd.service(8)
Main PID: 36360 (httpd)
Status: "Running, listening on: port 80"
Tasks: 213 (limit: 11221)
Memory: 38.6M
CGroup: /system.slice/httpd.service
├─36360 /usr/sbin/httpd -DFOREGROUND
├─36375 /usr/sbin/httpd -DFOREGROUND
├─36376 /usr/sbin/httpd -DFOREGROUND
├─36378 /usr/sbin/httpd -DFOREGROUND
└─36405 /usr/sbin/httpd -DFOREGROUND

If firewalld is enabled consider allowing HTTP and HTTPS services:

$ sudo firewall-cmd --permanent --add-service={http,https}
$ sudo firewall-cmd --reload

You can test to make sure everything is working correctly by navigating to:

http://your-IP-address

If everything is configured properly, you should be greeted by the default AlmaLinux Test Page, as seen below.

AlmaLinux Test Page
AlmaLinux Test Page

Install MariaDB 10.7

MariaDB 10.7 is the latest release version for this relational database system. To be able to install MariaDB 10.7 on AlmaLinux 8 you need to add the MariaDB YUM repository:

$ curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
$ sudo bash mariadb_repo_setup --mariadb-server-version=10.7

Once the repository has been added to the system, installing MariaDB is an easy task that can be accomplished with the following command:

$ sudo dnf install MariaDB-server MariaDB-client

Once the installation is complete, verify the installed version of MariaDB.

$ sudo dnf info MariaDB-server
MariaDB 10.7
MariaDB 10.7 on AlmaLinux 8.5

Start the database server daemon, and also enable it to start automatically at the next boot with the following commands:

$ systemctl start mariadb
$ systemctl enable mariadb

Check the status of the service:

$ systemctl status mariadb

Example output:

$  mariadb.service - MariaDB 10.7.1 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) 
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 35787 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 13 (limit: 11221)
Memory: 68.0M
CGroup: /system.slice/mariadb.service
└─35787 /usr/sbin/mariadbd

Secure MariaDB

Run mariadb-secure-installation script which helps you secure your MariaDB database server:

$ sudo mariadb-secure-installation

You can set a root password for MariaDB along with removing empty databases, restricting remote access except for localhost, removing anonymous users, and more:

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

Install PHP 8.1

Currently, PHP 8.1 is not featured in AlmaLinux’s AppStream. However, you can install PHP from (Remi) repository, a free-to-use third-party repository that deploys the latest PHP 8.1 builds.

To install EPEL, use the following (dnf) terminal command:

$ sudo dnf install epel-release

Now that you have added the EPEL repository, enable (Remi repository) with the following command:

$ sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

Use the (dnf) command to update your repository list:

$ sudo dnf update

Next, enable PHP 8.1 with the following command:

$ sudo dnf module enable php:remi-8.1

Now that you have added the Remi PHP repository and enabled PHP 8.1 to be the default version on your system, you can install PHP 8.1 with the following command:

$ sudo dnf install php

You can check your PHP version using the following command:

$ php -v

Example output:

PHP 8.1.1 (cli) (built: Dec 15 2021 02:00:45) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies

If you would like to install the most commonly used extensions for PHP 8.1, use the following command:

$ sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache

You can check your PHP modules using the following command:

$ php -m

Example output:

[PHP Modules]
..............
igbinary
imagick
imap
intl
json
libxml
mbstring
memcache
memcached
msgpack
mysqli
mysqlnd
openssl
..............

[Zend Modules]
Zend OPcache

Comments and Conclusion

In the tutorial, you have learned how to install LAMP stack on AlmaLinux 8.

If you have any questions please leave a comment below.

1 thought on “How to Install LAMP Stack on AlmaLinux 8.5

Leave a Reply

Your email address will not be published.