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.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

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.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

1 Response

  1. NaheemSays says:

    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

Leave a Reply to NaheemSays Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.