Install LAMP Stack on Red Hat Enterprise Linux 8 - Step by Step Process ?



The LAMP stack is a set of open-source tools used in web development. LAMP represents Linux, Apache HTTP Server, MySQL/MariaDB, and PHP.

Linux is the operating system; 

Apache is the web server; 

MariaDB/MySQL is the database server and PHP is the server-side scripting language responsible for generating dynamic web pages.

Here at LinuxReels, as part of our Server Management Services, we regularly help our Customers to perform related LAMP queries.

In this context, we shall look into how you can install the LAMP stack on Red Hat Enterprise Linux (RHEL) 8.


How to install Apache HTTP Server on Red Hat Enterprise Linux 8 ?

To begin, ensure you are using a user with sudo privileges on RHEL 8. 

The Apache HTTP Server is one of the oldest and most popular web servers. 

It is available as httpd on RHEL 8. 

i. Firstly, run the command below to check for package updates:

$ sudo dnf update

ii. Next, install the Apache HTTP server on RHEL 8 as follows:

$ sudo dnf install httpd

You would be prompted to enter y to continue with the installation.

iii. Once httpd is successfully installed, check the status with the command below:

$ sudo systemctl status httpd

iv. Press q to return to the command prompt.

v. If the status of httpd is inactive, then start the service with the next command:

$ sudo systemctl start httpd


Once you see that the Apache HTTP Server is active, you may open a web browser and enter the IP address of your RHEL 8 server. 

Or simply enter localhost if you are directly connected to the server.

You should see the Red Hat Enterprise Linux Test Page.


To configure the Apache HTTP Server to automatically start when the system boots, run the command below.

$ sudo systemctl enable httpd

This takes care of the second component of the LAMP stack, i.e., Apache.


How to install MariaDB on Red Hat Enterprise Linux 8 ?

MariaDB is a free and open-source relational database management system. MariaDB was derived from MySQL after MySQL was acquired by Oracle Inc.


i. To install MariaDB on RHEL 8, run the command below.

$ sudo dnf install mariadb-server -y

ii. After MariaDB is successfully installed, check the status of the service with:

$ sudo systemctl status mariadb

iii. Press q to return to the command prompt.

iv. If MariaDB is not active, start the service with the next command.

$ sudo systemctl start mariadb

Check the status again to confirm that MariaDB is now active.

v. Run the next command to configure MariaDB to automatically start when the system boots:

$ sudo systemctl enable mariadb

vi. Next, run the following to execute a built-in script for securing MariaDB:

$ mysql_secure_installation

You would be prompted to take a series of actions. 

Please read the instructions carefully while you follow the prompts.

In summary, you would be asked to:

1. Enter current password for root. This is blank on a new installation of MariaDB. So just hit the enter key
2. Set root password
3. Remove anonymous users
4. Disallow root login remotely
5. Remove test database and access to it
6. Reload privilege tables to save changes

vii. Once you are done securing MariaDB, login as follows:

$ sudo mysql -u root -p

You should see the MariaDB prompt which confirms that the third component of the LAMP stack is working okay.

viii. Finally, Enter quit to exit MariaDB.


How to install and test PHP on on Red Hat Enterprise Linux 8 ?

PHP (i.e., Hypertext Preprocessor) is a server-side scripting language for creating dynamic web pages and apps. PHP interacts with databases and dynamically generates content based on client requests.

i. Run the command below to install PHP and related modules on RHEL 8.

$ sudo dnf install php -y

ii. After installation, check the version of PHP with:

$ php -v

iii. To test PHP, create an index.php file in the default website root as follows.

$ sudo nano /var/www/html/index.php

iv. Copy and paste the sample PHP code below:

<?php
phpinfo();
?>

v. Save and close the index.php file.

vi. Open a web browser and go to yourserverip/index.php or localhost/index.php.


[Need to configure Apache web Server on your Linux System ? We can help. ]


Conclusion:

This article covers the installation of the LAMP stack (i.e., Linux, Apache, MariaDB, and PHP) on RHEL 8.

LAMP stands for Linux, Apache, MariaDB/MySQL and PHP, all of which are open source.


With the yum commands below, install LAMP stack:

# Will automatically update

$ sudo yum -y update

# Will automatically install Apache/HTTPD

$ sudo yum -y install httpd


To Install MariaDB Database Server on CentOS 8/RHEL 8:

1. Enter the following command to install MariaDB on CentOS 8/RHEL 8.

# dnf install mariadb-server mariadb -y

2. After it's installed, we need to start it.

# systemctl start mariadb

3. Enable auto start at system boot time.

# systemctl enable mariadb

4. Check status:

# systemctl status mariadb