Red Hat

Install LAMP Stack on Red Hat Enterprise Linux 8

Install LAMP Stack on Red Hat Enterprise Linux 8

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

This guide will show you how you can install the LAMP stack on Red Hat Enterprise Linux (RHEL) 8.

Prerequisite

In order to follow along, you would require a user with sudo privileges on RHEL 8. This takes care of the first component of the LAMP stack, i.e., Linux.

Install Apache HTTP Server

The Apache HTTP Server is one of the oldest and most popular web servers. It is available as httpd on RHEL 8. Firstly, run the command below to check for package updates.

$ sudo dnf update

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.

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

$ sudo systemctl status httpd

Press q to return to the command prompt.

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 as shown below.

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.

Install MariaDB

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

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

$ sudo dnf install mariadb-server -y

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

$ sudo systemctl status mariadb

Press q to return to the command prompt.

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.

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

$ sudo systemctl enable mariadb

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

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.

Enter quit to exit MariaDB.

Install PHP

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.

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

$ sudo dnf install php -y

After installation, check the version of PHP with:

$ php -v

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

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

Copy and paste the sample PHP code below.

<?php

phpinfo();

?>

Save and close the index.php file.

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

If you see something similar to what is shown in the image above, then PHP is working fine. That takes care of the fourth and final component of the LAMP stack.

Conclusion

This guide covered the installation of the LAMP stack (i.e., Linux, Apache, MariaDB, and PHP) on RHEL 8. Let us know if you have any comments or questions.

 

Similar Posts