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

Channel: RedHat Linux
Abstract: start the web server and verify the status using the commands below. # systemctl enable httpdInstall PHP on RHEL 8 6. Now restart your web server so t

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

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

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

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 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

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 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

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

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

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 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.

Ref From: tecmint

Related articles