How To Install Linux, Apache, MySQL, PHP (LAMP) stack On RHEL 8

How To Install Linux, Apache, MySQL, PHP (LAMP) stack On RHEL 8

Install Linux, Apache, MySQL, PHP, How do I set up a LAMP stack on RHEL eight cloud server or VPS or naked metal server? How can I installation Linux, Apache, MySQL/MariaDB, PHP (LAMP) stack On RHEL (Red Hat Enterprise Linux) eight?

Introduction – A LAMP stack is not anything but a collection of popular software program established to build and run dynamic websites and apps. Typical examples of LAMP consists of WordPress primarily based weblog, Wiki coded in Mediawiki, or custom made e-commerce site. LAMP is an acronym for the:

  • Linux OS
  • Apache net server
  • MySQL or MariaDB server to shop statistics
  • PHP for a server-aspect dynamic web era programming language

How to set up and install Linux, Apache, MySQL, PHP (LAMP) stack On RHEL 8

The manner to set up a LAMP stack on a Red Hat Enterprise Linux:

  1. Update your machine by way of strolling sudo dnf replace
  2. Install Apache HTTPD in RHEL eight: sudo dnf deploy httpd
  3. Set up MariaDB (MySQL clone) on RHEL eight sudo dnf set up mariadb-server
  4. Finally installation PHP 7.X to finish a LAMP installation on RHEL eight, run sudo dnf set up @personal home page
  5. Test your LAMP setup

Let us see all commands in information.

Install Linux, Apache, MySQL, PHP,Step 1 – Update RHEL eight field

Simply run the subsequent dnf command:

 $ sudo dnf replace

Install Linux, Apache, MySQL, PHP,Step 2 – Install Apache (HTTPD) on RHEL 8

Again use the dnf command:

 $ sudo dnf deploy httpd
How to install HTTPD on RHEL 8

Install Linux, Apache, MySQL, PHP,How to allow httpd carrier

he httpd.Carrier disabled by using default. To begin the httpd service at boot time, run the following systemctl command:

sudo systemctl permit httpd.Service

In the default configuration, the httpd daemon will accept connections on port eighty (and, if mod_ssl is mounted, TLS connections on port 443) for any configured IPv4 or IPv6 address.

Install Linux, Apache, MySQL, PHP,Command to start/stop/restart httpd

sudo systemctl start httpd.service ## <- Start Apache ##
sudo systemctl stop httpd.service ## <- Stop Apache ##
sudo systemctl restart httpd.service ## <- Restart Apache ##
sudo systemctl reload httpd.service ## <- Reload Apache ##
sudo systemctl status httpd.service ## <- Get status of Apache ##

Verify that port 80 open by running the ss command along with grep command:

$ sudo ss -tulpn
$ sudo ss -tulpn | grep :80
How to enable and start HTTPD service on RHEL 8

Install Linux, Apache, MySQL, PHP,How to open port 80 using firewalld

By default firewalld on RHEL eight would block get right of entry to to HTTP TCP port # 80.To open HTTP port 80 on a RHEL eight, run:

$ sudo firewall-cmd --permanent --add-service=http --zone=public
$ sudo firewall-cmd --reload
$ sudo firewall-cmd --list-services --zone=public
How to open Apache port 80 using firewalld command on RHEL 8

Install Linux, Apache, MySQL, PHP,Test it

Use the ip command to find out your public IP address on a RHEL 8:

ip a<br>ip a s ens3<br>ip a s eth0<br>ip a s ens3 | grep -w inet | awk '{ print $2}'

Fire a web browser and type url:


OR use FQDN:

The default RHEL 8 Apache web page

Step 3 – Install MariaDB on RHEL 8

Our Apache is running. It is time to install MariaDB which acts as a drop replacement for Oracle MySQL server. Type the following dnf command:

$ sudo dnf install mariadb-server
Installing MariaDB on RHEL 8 using the dnf/yum command

Enable and start/stop/restart MariaDB service

Turn on MariDB server at boot time, run:

$ sudo systemctl enable mariadb.service

To stop/stop/restart MariDB service use the following systemctl command:

sudo systemctl start mariadb.service ## &lt;- Start MariaDB server ##
sudo systemctl stop mariadb.service ## &lt;- STOP MariaDB server ##
sudo systemctl restart mariadb.service ## &lt;- RESTART MariaDB server ##
sudo systemctl status mariadb.service ## &lt;- Get status of MariaDB server ##

Finally secure you MariaDB server, run:

$ sudo mysql_secure_installation
Securing MariaDB server on RHEL 8

Step 4 – Install PHP 7.X on RHEL 8

Now your Apache server and database structures are up and going for walks. It is time to put in the very last piece of the puzzle. Type the following dnf command to put in PHP 7.2 at the side of popular PHP modules to get right of entry to MySQL from PHP, images and extra:

$ sudo dnf install php php-mysqlnd php-mbstring php-opcache php-gd
How to install PHP 7.2 on RHEL 8

You must restart httpd service to access PHP:

$ sudo systemctl restart httpd.service

A note about searching and installing additional PHP modules

PHP comes with many modules. You want to put in them as in step with your wishes. You can look for modules using the subsequent syntax:

$ sudo dnf search php-
$ sudo dnf search php- | grep -i mysql

Find info about php-mbstring, run

$ dnf info {php_module_package_name_here}
$ sudo dnf info php-mbstring

Install php-mbstring, run:

$ sudo dnf install php-mbstring

Test your PHP installation

Create a file named test.php in /var/www/html/ directory:

$ sudo vi /var/www/html/test.php

Append the following php code:


Save and close the file. Test your PHP. Fire a web browser and type url:
The address you want to visit will be:



Testing PHP 7.2 on RHEL 8 LAMP setup

If you see the output as above, then your PHP is installed and working correctly. You can delete the file using rm command:

$ sudo rm /var/www/html/test.php

How to see log files for my Apache server

Use the cat command/tail command as follows to Apache/httpd logs on RHEL eight:

ls -l /var/log/httpd/
sudo tail -f /var/log/httpd/access_log
sudo grep 'foo' /var/log/httpd/error_log

How do I configure HTTPD further?

All Apache configuration files are as follows:

  • /etc/httpd/ – Main Apache config directory
  • /etc/httpd/conf/httpd.conf – Main Aapache config file. You can edit this file running sudo vi /etc/httpd/conf/httpd.conf command
  • /var/log/httpd/ – Apache error and access log files
  • /etc/httpd/conf.modules.d – Apache modules (such as proxy, php and more) config directory


That is all for now. You successfully set up a LAMP server on RHEL 8. Next time you will learn about securing Apache server using TLS/SSL.