How to Install Apache, MariaDB and PHP on Rocky Linux 9.2

This is one of the most commonly used Software Stack for building your web applications. This is also known as LAMP (Linux, Apache, MySQL/MariaDB, PHP/Perl/Python) Stack.

Update Rocky Linux 9.2 Software Packages


Let's update software packages first. To perform updates, run the following command:

dnf update

Install Apache Web Server


First, we will start by installing the Apache webserver. To complete the installation, use the following command:

dnf install httpd httpd-tools 

Output:

Once the installation is complete, enable Apache (to start automatically upon system boot), start the webserver, and verify the status using the commands below.

systemctl enable httpd

systemctl start httpd

systemctl status httpd

Output:

To make your pages available to the public, you will have to edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands.

firewall-cmd --permanent --zone=public --add-service=http

firewall-cmd --permanent --zone=public --add-service=https

firewall-cmd --reload

Output:

[root@server ~]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@server ~]# firewall-cmd --permanent --zone=public --add-service=https
success
[root@server ~]# firewall-cmd --reload
success

Verify that the webserver is running and accessible by accessing your server’s IP address from your browser,

http://IP_address

Replace the IP_address with the actual IP of the server.

Install MariaDB Server


MariaDB is a popular database server. The installation is simple and requires just a few steps as shown.

dnf install mariadb-server mariadb -y

Output:

Once the installation is complete, enable MariaDB (to start automatically upon system boot), start the MariaDB, and verify the status using the commands below.

systemctl start mariadb

systemctl enable mariadb

systemctl status mariadb

Output:

Finally, you will want to secure your MariaDB installation by issuing the following command.

mysql_secure_installation

Output:

Once secured, you can connect to MySQL and review the existing databases on your database server by using the following command.

mysql -e "SHOW DATABASES;" -p

Output:

[root@server ~]# mysql -e "SHOW DATABASES;" -p
Enter password:
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
[root@server ~]#

Done!

Install PHP 8


To install PHP on your RHEL 8 use the command below.

yum install php php-mysqlnd php-pdo php-gd php-mbstring

sudo dnf install php php-curl php-bcmath php-gd php-soap php-zip php-curl php-mbstring php-mysqlnd php-gd php-xml php-intl php-zip

Now restart your web server so that Apache knows that it will be serving PHP requests as well.

systemctl restart httpd 

Test your PHP, by creating a simple info.php file with a phpinfo() function in it. The file should be placed in the directory root for your web server, which is /var/www/html.

To create the file use:

echo "<?php phpinfo() ?>" > /var/www/html/info.php

Now again, access http://localhost/info.php or http://yourserver-ip-address/info.php. You should see a page similar to the below one.

Was this answer helpful?

Related Articles

What is a Dedicated Server?

A dedicated server provides dedicated internet hosting on a physical server that is attached to a...

What is server hosting?

Server hosting is a huge benefit for any size business or organization. Server hosting is the...

Do I need a Dedicated Server for my website?

A dedicated server is a resource-rich machine that is typically used by organizations with heavy...

Are your Dedicated Servers managed?

We offer both cPanel Managed Dedicated Servers and Unmanaged Dedicated Servers, often referred to...

How to Install cPanel/WHM on CentOS 7

Installation Requirements A clean fresh minimal installation of CentOS 7 server. Minimum of 1...

Powered by WHMCompleteSolution