How To Install Linux, Apache, MariaDB, PHP (LAMP Stack) on RHEL 8

0

LAMP Stack stands for Linux, Apache, MariaDB, and PHP stack. Here is the small guide about installing and configuring web server stack with the latest release of RHEL 8.

Install Linux

Install the Red Hat Enterprise Linux 8 using the below link

READ: Step by Step Guide To Install RHEL 8 with Screenshots

By this time, you should have a Linux machine ready with you. Now, we will install Apache, MariaDB, and PHP on top of it.

The steps mentioned in this article will only work if you have enabled RHEL 8 subscription or configured the local yum repository on your system.

Switch to the root user.

$ su -

Install Apache Web Server

Let us start installing the Apache web server. The package name of the Apache server is httpd. Install the httpd rpm package using the YUM command.

In RHEL 8, ensure rhel-8-for-x86_64-baseos-rpms and rhel-8-for-x86_64-appstream-rpms enabled on your system.
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

Output:

Install LAMP Stack On RHEL 8 - Apache Web Server Service Status
Install LAMP Stack On RHEL 8 – Apache Web Server Service Status

Firewall

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

Test Apache

Open up a web browser and then enter the following URL into the web address.

http://localhost

OR

http://your.ip.adr.ess

You will get the below Apache test web page. This test page confirms that the Apache is working fine.

Install LAMP Stack on RHEL 8 - Apache Web Server Test Page
Install LAMP Stack on RHEL 8 – Apache Web Server Test Page
Apache’s default document root is /var/www/html on RHEL, and the main configuration file is /etc/httpd/conf/httpd.conf. Additional configurations for Apache Web server are stored in /etc/httpd/conf.d/ directory.

Install MariaDB

Next, we will install the database server which is MariaDB. Type the following command in the terminal and press enter.

In RHEL 8, ensure rhel-8-for-x86_64-appstream-rpms repository enabled on your system.
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

Output:

Install LAMP Stack on RHEL 8 - MariaDB Server Status
Install LAMP Stack on RHEL 8 – MariaDB Server Status

Secure 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_.
mysql_secure_installation

Output:

Install LAMP Stack on RHEl 8 - Secure MariaDB Installation
Install LAMP Stack on RHEl 8 – Secure MariaDB Installation

Install PHP

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.

In RHEL 8, ensure rhel-8-for-x86_64-appstream-rpms repository enabled on your system.
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.

http://localhost/info.php

OR

http://you.ip.addr.ess/info.php

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.

Install LAMP Stack on RHEL 8 - Apache Web Server Test Page
Install LAMP Stack on RHEL 8 – Apache Web Server Test Page

Scroll down the browser to check the support for the MariaDB. You will get the screen like below.

Install LAMP Stack on RHEL 8 - MariaDB Support Information
Install LAMP Stack on RHEL 8 – MariaDB Support Information

Conclusion

I hope, this post helped you setup LAMP stack on RHEL 8. Please share your feedback in the comments section.

You might also like