How to install LAMP Stack on RHEL 8

Share on Social Media

In this guide, you will learn, how to install LAMP Stack on RHEL 8 or other Redhat based Linux OS. #centlinux #linux #apache #mysql #php

What is LAMP Stack? :

LAMP is the most widely used software service stack, used to deploy PHP based web applications. LAMP is named as acronym, derived from first letter of four original open-source components i.e. L from Linux, A from Apache, M from MySQL and P from PHP.

Here, we have selected Red Hat Enterprise Linux (RHEL) 8, Apache HTTP Server 2.4, MySQL 8.0 and PHP 7.2 as the LAMP Stack components.

Environment Specification:

A RHEL 8 minimal installed virtual machine is being used in this article. The specifications are:

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – Red Hat Enterprise Linux (RHEL) 8
  • Hostname – rhel-8-lamp.example.com
  • IP Address – 192.168.116.183/24

A Local YUM repository is configured, so we can install required packages without having an active Red Hat subscription.

Install Apache on RHEL 8:

Connect with rhel-8-lamp.example.com using ssh as root user.

Since, we have already configured local yum repository, therefore, we can easily install Apache HTTP Server using dnf command.

# dnf install -y httpd

Enable and start httpd.service.

# systemctl enable httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service â /usr/lib/systemd/system/httpd.service.
# systemctl start httpd.service

Allow HTTP service in Linux firewall.

# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --reload
success

Open URL http://rhel-8-lamp.example.com using a web browser.

Apache Default Homepage

Apache HTTP Server has been installed and running on our Linux server.

Install MySQL on RHEL 8:

For database back-end installation, we can choose between MySQL and MariaDB.

Since we have already used MariaDB in our previous article Install LEMP Stack on RHEL8 Server, therefore, we are installing MySQL this time.

MySQL 8.0 is available in local AppStream repository, therefore, let’s install it using dnf command.

# dnf install -y mysql-server

Start and enable MySQL service.

# systemctl enable mysqld.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service â /usr/lib/systemd/system/mysqld.service.
# systemctl start mysqld.service

Configure and secure MySQL database instance as follows.

# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

Verify MySQL database installation using following command.

# mysql -e "SHOW DATABASES;" -p

Enter password:
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

MySQL Database 8.0 has been installed on our Linux server.

Install PHP on RHEL 8:

In local AppStream repository, PHP 7.2 is available, therefore, we can install it simply by executing a dnf command.

# dnf install -y php php-mysqlnd php-mbstring php-pdo php-gd

During installation, PHP created necessary configuration file in Apache configuration directory. Therefore, we have to restart httpd.service to integrate PHP with Apache HTTP Server.

# systemctl restart httpd.service

Create a PHP file to verify PHP installation and its integration with Apache HTTP Service.

# echo "<?php phpinfo() ?>" > /var/www/html/info.php

Open URL http://rhel-8-lemp.example.com/info.php in a web browser.

PHPinfo Page

We have successfully install LAMP Stack on RHEL 8.

Conclusion – Install LAMP Stack on RHEL 8:

In this guide, you have learned, how to install LAMP Stack on RHEL 8 or other Redhat based Linux OS.

Scroll to Top