Share your love
How To Install LAMP Stack on AlmaLinux 8
In this article, we want to teach you How To Install a LAMP stack on AlmaLinux 8.
LAMP stands for Linux, Apache, MySQL, and PHP.
Together, they provide a proven set of software for delivering high-performance web applications.
Install a LAMP stack on AlmaLinux 8
Before you start to install the LAMP stack on AlmaLinux 8, you need to log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our article the Initial Server Setup with AlmaLinux 8.
Now follow the steps below to set up a LAMP stack on your server.
Install Apache on AlmaLinux 8
You need to install Apache as a web server on AlmaLinux 8. First, update your local package index with the following command:
sudo dnf update
Then, install Apache with the command below:
sudo dnf install httpd
When your installation is completed, start and enable your Apache service on AlmaLinux 8 with the commands below:
sudo systemctl enable httpd
sudo systemctl start httpd
Verify that your service is active and running on your server with the following command:
sudo systemctl status httpd
In your output you will see:
Output httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese> Active: active (running) since Mon 2022-01-03 09:00:37 EST; 34s ago Docs: man:httpd.service(8) Main PID: 89138 (httpd) Status: "Running, listening on: port 80" Tasks: 213 (limit: 11409) Memory: 37.6M CGroup: /system.slice/httpd.service ├─89138 /usr/sbin/httpd -DFOREGROUND ├─89139 /usr/sbin/httpd -DFOREGROUND ├─89140 /usr/sbin/httpd -DFOREGROUND ├─89141 /usr/sbin/httpd -DFOREGROUND └─89142 /usr/sbin/httpd -DFOREGROUND
Here we assumed that you have enabled firewalld from the requirements, now you need to allow traffic for Apache through the AlmaLinux firewall with the following command:
sudo firewall-cmd --add-service=http --permanent
Reload the firewall to apply the new rules:
sudo firewall-cmd --reload
Now you can access the Apache default page by typing your server’s IP address in your web browser:
http://server-IP-address
you will see:
Install MariaDB on AlmaLinux 8
At this point, you need to set up MariaDB as a database server on your AlmaLinux 8.
To install MariaDB, run the following command:
sudo dnf install mariadb-server mariadb
When your installation is completed, start and enable your service with the following command:
sudo systemctl enable mariadb
sudo systemctl start mariadb
Then, you need to secure your MariaDB installation with the following command:
sudo mysql_secure_installation
You will be asked some questions, answer them as shown below:
Enter current password for root (enter for none): Set root password? [Y/n] Y New password: Re-enter new password: Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Reload privilege tables now? [Y/n] Y
To log in to your MariaDB console you can use the following command:
sudo mysql -u root -p
Set up PHP on AlmaLinux 8
By default, PHP 7.4 is available in the default AlmaLinux repository. The latest version of PHP is PHP 8.1.
To install the latest PHP on AlmaLinux 8, run the command below to enable the Remi repository first:
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Then, get the available PHP modules on AlmaLinux 8 with the command below:
sudo dnf module list php
In your output you will see:
Output 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 php remi-8.1 common [d], devel, minimal PHP scripting language
The default module is PHP 7.2. Reset the default module with the command below:
sudo dnf module reset php
Then, enable the latest PHP module by using the following command:
sudo dnf module enable php:remi-8.1
Now you can install the latest PHP and its dependencies on AlmaLinux 8 with the command below:
sudo dnf install php php-fpm php-curl php-cli php-gd
When your installation is completed, verify your PHP installation by checking its version:
php -v
In your output you will see:
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
Also, you can test your PHP from your web server. To do this, create and open a smile PHP file with your favorite text editor, here we use vi:
sudo vi /var/www/html/info.php
Add the following content to the file:
<?php phpinfo(); ?>
When you are done, save and close the file.
Restart Apache to apply the changes:
sudo systemctl restart httpd
Now in your web browser type your server’s IP address followed by /info.php:
http://server-IP/info.php
You will see your PHP information in detail:
After you have read your PHP info, for more security it’s better to remove it with the command below:
sudo rm /var/www/html/info.php
Conclusion
At this point, you learn to set up the LAMP stack on AlmaLinux 8.
I hope you enjoy using it.
May you will be interested in these articles:
How To Install and Configure Netdata on AlmaLinux 8.