RedHat 8 – Install and Configure Apache Web Server with Virtual Host

Learn how to install and configure Apache Web Server on the new Red Hat 8 Systems. Create your first virtual host and learn how to manage the hpptd service.

Learn how to Install Apache Web Server on the new Red Hat 8, Apache is an Open Source project from Apache Foundation.

Apache service on Red Hat is called as httpd and runs on port 80 for HTTP and port 443 for HTTPS.

Tutorial objectives

Install Apache Web Server

  • Install Apache Web Server on Red Hat 8
  • Configure One Virtual Host
  • Configure Logs Folder
  • Open Firewall for Apache

Update Red Hat 8 System

First of all let’s update our system to get the latest packages, Red Hat 8 use version 2.4.37 of Apache HTTP Server.

sudo yum update

Install the httpd service on Red Hat 8

After update the system let’s install the httpd service.

sudo yum install -y httpd
Install httpd service package
Install httpd service package

Manage the httpd service on Red Hat 8

To manage the httpd service we have many options as systemd offer, on this example we only use the option start, enable and reload.

Start the httpd Service

sudo systemctl start httpd

Verify the httpd service status

sudo systemctl status httpd
Checking httpd Status
Checking httpd Status

Reload the httpd service after saving a new configuration

sudo systemctl reload httpd

Enable the httpd service at system boot

sudo systemctl enable httpd
Load httpd service on boot
Load httpd service on boot

Verify system associated IPs

hostname -I

Create a folder for website data

sudo mkdir -p /var/www/certificationsnotes.local/html

Create a folder to storage website logs, we can create it on other folder just adjust it on virtual host configuration.

sudo mkdir -p /var/www/certificationsnotes.local/log

Change the ownership of all files recursively on the website folder to the current user.

sudo chown -R $USER:$USER /var/www/certificationsnotes.local/html

Change the folder permissions to 755

sudo chmod -R 755 /var/www

Create an html index page to use as an example.

sudo vi /var/www/certificationsnotes.local/html/index.html
sudo mkdir /etc/httpd/sites-available /etc/httpd/sites-enabled
sudo vi /etc/httpd/conf/httpd.conf
IncludeOptional sites-enabled/*.conf

Red Hat 8 Create Virtual Hosts

What is a Virtual Host? A Virtual Host is a website configuration on Apache Web Server in theory we can configure many websites we want the only limitation is Hardware.

sudo vi /etc/httpd/sites-available/certificationsnotes.local.conf
  <VirtualHost *:80>
    ServerName www.certificationsnotes.local
    ServerAlias certificationsnotes.local
    DocumentRoot /var/www/certificationsnotes.local/html
    ErrorLog /var/www/certificationsnotes.local/log/error.log
    CustomLog /var/www/certificationsnotes.local/log/requests.log combined
  </VirtualHost>
sudo ln -s /etc/httpd/sites-available/certificationsnotes.local.conf /etc/httpd/sites-enabled/certificationsnotes.local.conf

Now let’s add an entry on firewalld to allow HTTP protocol and HTTPS

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload
apachectl configtest

Red Hat

Apache Foundation

  • Install Red Hat 8
  • Configure Red Hat 8 Subscription
  • Red Hat 8 How to Fix Network IP Address using nmcli
  • Red Hat 8 How to define system Hostname

One comment

  1. […] Red Hat 8 – Install and Configure Apache Web Server with Virtual Host RedHat Certified System Administrator – RHCSA […]

Leave a Reply