How To Install Linux, Apache, MariaDB, PHP (LAMP Stack) on RHEL 8
Install the Red Hat Enterprise Linux 8 using the below link
Switch to the root user.
$ su -
Install Apache Web Server
yum install -y httpd
Start the Apache web service by using the systemctl command.
systemctl start httpd
Make the Apache server to start automatically. Type the following command on terminal and press enter.
systemctl enable httpd
Check the Apache Web server status using the below command.
systemctl status httpd
By default, the system firewall blocks the HTTP connections coming from external machines. So, to test or use the Apache web server, we need to configure the firewall to allow HTTP requests from external machines.
firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload
Open up a web browser and then enter the following URL into the web address.
You will get the below Apache test web page. This test page confirms that the Apache is working fine.
Next, we will install the database server which is MariaDB. Type the following command in the terminal and press enter.
yum install -y mariadb mariadb-server
Start the MariaDB server service using the systemctl command.
systemctl start mariadb
Enable the MariaDB server to start during every boot.
systemctl enable mariadb
Check the MariaDB server status using the below command.
systemctl status mariadb
Nex is to make the MariaDB server secure by using the mysql_secure_installation command.
This command enables you to improve the security of your MariaDB installation in the following ways:
- Set a password for root accounts.
- Remove root accounts that are accessible from outside the localhost.
- Delete anonymous-user accounts.
- Remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
By default, the Apache web server supports the HTML language only, not PHP. To have PHP support, we will need to install the PHP rpm package along with support for the MariaDB database.
yum install -y php php-mysqlnd
Restart the Apache Web server after the installation of the PHP to take an effect of PHP installation.
systemctl restart httpd
Test LAMP Stack
To test PHP, we will place a .php file on to the default directory of the Apache.
echo "<?php phpinfo()?>" > /var/www/html/info.php
Now open your web browser and type the following URL into the web address.
The page will look like below.
You will see lots of useful information about our PHP installation, such as the installed PHP version, PHP extension details, etc.
Scroll down the browser to check the support for the MariaDB. You will get the screen like below.
I hope, this post helped you setup LAMP stack on RHEL 8. Please share your feedback in the comments section.