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
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
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
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.
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
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.
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
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
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:
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
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.
I am a beginner and this tutorial was useful in installing my environment.
Regards,
Vijeyraghavan
Browsing to
http://localhost/info.php
not working. Chrome doesn’t find it and tries to search for it on Google. Browsing tohttp://localhost
does show the standard RHEL Apache /usr/share/testpage/index.html web page.Red Hat Enterprise Linux release 8.6 (Ootpa)
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