How to install Apache, MySQL and PHP on AlmaLinux 8

Steps to Install LAMP on AlmaLinux 8 #

The steps are described here to install and set up a Lamp server on AlmaLinux 8 can also be used for CentOS 8 Stream and RHEL 8 Linux server or desktop systems.

1. Run system update #

One of the necessary steps before running the installation programs is to run the command to update the system. This helps us to make sure all the installed packages are in their latest state but also rebuild the system repository cache. This helps in the process of any software or services installation running smoothly.

Code
sudo dnf update
Run system update
Run system update

Write ” y ” and Enter.

2. Install Apache web server on AlmaLinux 8 #

The next step is to install the Apache webserver on AlmaLinux along with some other tools to run httpd on this free RHEL based on Linux operating system. Now install the Apache package with the following command:

Code
sudo dnf install httpd httpd-tools
Command to install Apache on AlmaLinux 8
Command to install Apache on AlmaLinux 8

again, Write ” y ” and Enter.

3. Enable and start Apache #

Once the webserver is installed, let’s start its service and also make it automatically up with the system boot. This will ensure whenever you boot AlmaLinux you won’t need to start Apache manually.

Code

sudo systemctl start httpd
sudo systemctl enable httpd

After installing Apache and applying its settings, we will now check its Status:

Code
sudo systemctl status httpd
Check Apache Status in Almalinux 8
Check Apache Status in Almalinux 8

4. Update FireWall rules #

If you want to access the Apache webserver outside your local machine using some browser, then first we have to open ports 80 and 443 on our AlmaLinux server.

How open port 80 or HTTP in Almalinux 8 :
#
Code
sudo firewall-cmd --permanent --zone=public --add-service=http
How open port 443 or HTTPS in Almalinux 8:
#
Code
sudo firewall-cmd --permanent --zone=public --add-service=https

Reload firewall to make changes into effect:

Code
sudo firewall-cmd --reload

Well the installation is complete! Now by entering the IP address in the browser we can see the result:

http://your-server-ipadress

 

5. Install MySQL (MariaDB) on AlmaLinux8 #

MySQL is a freely available open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). SQL is the most popular language for adding, accessing, and managing content in a database. It is most noted for its quick processing, proven reliability, ease and flexibility of use.

MariaDB is a fork that works similarly and uses the same command line as MySQL. You can install any of them as per your choice. 

MySQL installation command:
#
Code
sudo dnf install mysql-server mysql

 

MariaDB installation command: #

Code
sudo dnf install mariadb-server mariadb -y

How Start & Enable MySQL and MariaDB services on Almalinux :
#

 

MySQL:

Code

sudo systemctl start mysqld
sudo systemctl enable mysqld

—–  check status

Code
sudo systemctl status mysqld

MariaDB

Code
sudo systemctl start mariadb
sudo systemctl enable mariadb

—–  check status

Code
sudo systemctl status mariadb

6. Secure MySQL installation #

This step will be the same whether you are using MySQL or MariaDB, it will give some options to follow and set some settings so that we can secure of Database from any common future threats.

Code
mysql_secure_installation

in this process, You will be asked to Set root PasswordRemove anonymous users, Disallow root login remotely, Remove test database, Reload privilege tables, and need Enter ” Y ” to do them.

  • Enter current password for root (enter for none): Enter
  • Set a 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
Secure MariaDB Installation

 

7. Install PHP 7.2/7.3/7.4 or 8.0 on AlmaLinux 8 #

PHP (recursive acronym for PHP: Hypertext Preprocessor) is an open-source, popular general-purpose scripting language that is widely-used and best suited for developing websites and web-based applications. It is a server-side scripting language that can be embedded in HTML.

Currently, there are three supported versions of PHP, i.e PHP 5.6, 7.0, and 8.0. Meaning PHP 5.3, 5.4, and 5.5 have all reached the end of life; they are no longer supported with security updates.

First, check what are PHP versions available to install:

Code
$ sudo dnf module list php
Search PHP modules or versions available to install on AlmaLinux 8
Search PHP modules or versions available to install on AlmaLinux 8

The output clearly shows that the default module is PHP 7.2 with the [d] tag.

To install PHP 7.4, first enable the module as provided.

Code

sudo dnf module reset php

sudo dnf module enable php:7.4

NOTE: To enable a different module, simply replace 7.4 with the preferred version. For example, to enable 7.3 run:

Once installed, install PHP and associated PHP extensions (php-extension_name) as indicated. The PHP extensions installed in this example are as shown.

Code

sudo dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd

Install the latest version of PHP on AlmaLinux 8
Install the latest version of PHP on AlmaLinux 8

To get better performance for various applications using PHP, we can start (if not already) and enable PHP-FPM (FastCGI Process Manager) using the below commands:

Code

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

 

8. Verify the Version of PHP Installed #

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

Code
$ php -v
Verify PHP Version
Verify PHP Version

The output above confirms that we have successfully installed PHP 7.4.
But since we have installed Apache web server and php, it is better to see if PHP works properly with web server?

So we create a file called test.php in the following path and open it with our favorite editor:

Code
sudo nano /var/www/html/test.php

Add the following line in the test.php file we have created using the above command:

Code
<?php
phpinfo ();
?>

To save the file type: Ctrl+X, press the Y key, and then Enter key.

Now, open your browser and type your server IP address along with file name test.php, we have created above:

http://your-server-ipaddress/test.php
Check PHP configuration details
Check PHP configuration details

 

9. Install PHP 8.0 (remi) on AlmaLinux 8 #

If you want to install the php version you want with the remi repository (for example, install php 8) follow these steps:

1. Add Remi Repository  #
Code
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm

2. Run system update #
Code
sudo dnf update
3. Check available Latest PHP versions #

Code
sudo dnf module list php
Remi on Almalinux
Remi on Almalinux

To install it first you have to set Remi’s PHP 8.0 as the default version to install on AlmaLinux 8, for that run:

Code

sudo dnf module reset php
sudo dnf module enable php:remi-8.0

Code
sudo dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd
Code

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

 

10. Install phpMyAdmin on Almalinux 8
#

If you also want to manage your MySQL or MariaDB database using web graphical user interface then see our article: Install phpMyAdmin on AlmaLinux 8 with Apache

Powered by BetterDocs