How to Install Apache, MySQL/MariaDB and PHP on RHEL 8

In this tutorial, you are going to learn how to install LAMP stack – Linux, Apache, MySQL/MariaDB, PHP on RHEL 8 system. This tutorial presumes that you have already enabled your RHEL 8 subscription and that you have root access to your system.

Step 1: Install Apache Web Server

1. First, we will start by installing the Apache web server, is a great web server that powers millions of websites across the internet. To complete the installation, use the following command:

# yum install httpd
Install Apache on RHEL 8
Install Apache on RHEL 8

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

# systemctl enable httpd
# systemctl start httpd
# systemctl status httpd
Enable and Start Apache on RHEL 8
Enable and Start Apache on RHEL 8

3. To make our pages available to public, we will have to edit our firewall rules to allow HTTP requests on our web server using the following commands.

# firewall-cmd --permanent --zone=public --add-service=http 
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
Open Apache Access on Firewalld
Open Apache Access on Firewalld

4. Verify that the web server is running and accessible by accessing either http://localhost or your server’s IP address. You should see a page similar to the one below.

Verify Apache on RHEL 8
Verify Apache on RHEL 8

Step 2: Install PHP Programing Language

5. Our next step is to install PHP – programing language used on many websites such as WordPress and Joomla, due to its extremely powerful and flexible behavior.

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

# yum install php php-mysqlnd php-pdo php-gd php-mbstring
Install PHP on RHEL 8
Install PHP on RHEL 8

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

# systemctl restart httpd 

7. Test your PHP, by creating a simple info.php file with a phinfo() 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://server-ip-address/info.php. You should see a page similar to this one.

Check PHP Info on RHEL 8
Check PHP Info on RHEL 8

Step 3: Install MariaDB Server

8. MariaDB is a popular database server, used in many environments. The installation is simple and requires just a few steps as shown.

# yum install mariadb-server mariadb
Install MariaDB on RHEL 8
Install MariaDB on RHEL 8

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

# systemctl enable mariadb
# systemctl start mariadb
# systemctl status mariadb
Enable and Start MariaDB on RHEL 8
Enable and Start MariaDB on RHEL 8

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

# mysql_secure_installation

You will be asked a few different questions regarding your MariaDB installation and how you would like to secure it. You can change the database root user password, disable the test database, disable anonymous users, and disable root login remotely.

Here is an example:

Secure MariaDB Installation on RHEL 8
Secure MariaDB Installation on RHEL 8

11. 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
Check MySQL Databases in RHEL 8
Check MySQL Databases in RHEL 8
Conclusion

In this tutorial, we’ve shown how to install the famous LAMP stack on your RHEL 8 system. The process was easy and straightforward, but if you have any questions, please post them in the comment section below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Marin Todorov
I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 Comments

Leave a Reply
  1. Browsing to http://localhost/info.php not working. Chrome doesn’t find it and tries to search for it on Google. Browsing to http://localhost does show the standard RHEL Apache /usr/share/testpage/index.html web page.

    Red Hat Enterprise Linux release 8.6 (Ootpa)

    Reply
  2. For future proofing, I would guess using the module install method for php would be better. It lets you swap out the module for a newer one in the future

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.