How to install LAMP Stack on RHEL 8

Share on Social Media

Learn how to install LAMP Stack on RHEL 8 with our comprehensive guide. Follow step-by-step instructions to set up and configure your LAMP Stack efficiently on your RHEL 8 system. #centlinux #linux #apache #mysql #php

What is LAMP Stack?

LAMP stack is a popular combination of open-source software widely used for building and deploying web applications. LAMP is an acronym that stands for the following four essential components:

LAMP Stack Components

  1. Linux:
    • Role: The operating system for the stack. Linux provides a stable, secure, and efficient environment for running web applications.
    • Features: Open-source, customizable, robust security features, and extensive community support.
  2. Apache:
    • Role: The web server that serves web pages to users.
    • Features: Open-source, highly configurable, supports various modules and extensions, and is known for its stability and flexibility.
  3. MySQL/MariaDB:
    • Role: The relational database management system (RDBMS) used to store application data.
    • Features: MySQL is known for its speed and reliability, while MariaDB is a MySQL fork with additional features and enhancements. Both support complex queries, transactions, and data management.
  4. PHP:
    • Role: The server-side scripting language used to create dynamic web content.
    • Features: Widely used for web development, easy to integrate with HTML, and has a large community and extensive libraries.

Advantages of the LAMP Stack

  • Performance: Apache is a robust web server capable of handling a variety of web applications, while MySQL/MariaDB offers high performance for data management.
  • Flexibility: The components are highly configurable and can be tailored to specific needs.
  • Scalability: The stack can be scaled up or out to handle increasing traffic and data loads.
  • Security: Linux and Apache offer strong security features, and MySQL/MariaDB provides various security options for data protection.
  • Cost-Effective: All components of the LAMP Stack are open-source and free to use.
  • Community Support: Each component has an active community, providing extensive documentation, forums, and resources for support and troubleshooting.

Common Use Cases for the LAMP Stack

  • Web Hosting: Ideal for hosting websites and web applications.
  • Content Management Systems (CMS): Supports CMS platforms like WordPress, Drupal, and Joomla.
  • E-Commerce Platforms: Can be used to build and manage online stores.
  • Custom Web Applications: Suitable for developing and deploying custom web applications.

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.

Recommended Online Training: Learn Bash Shell in Linux for Beginners

745772 0021

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 Page
Apache Default Page

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
PHPInfo Page

We have successfully install LAMP Stack on RHEL 8.

If you are new to Linux and facing difficulty in working at Linux Bash prompt. We recommend that, you should read The Linux Command Line, 2nd Edition: A Complete Introduction by William Shotts.

Final Thoughts

If you found this guide on installing the LAMP Stack on RHEL 8 helpful and need further assistance with server setup or other technical support, consider hiring a professional. Visit my Fiverr profile for expert services in server configuration, database management, and more. Let’s make your project a success!

Leave a Comment