Unix/Linux Guru and FOSS supporter

How to install Virtual hosts on apache (Centos8)

What is Apache ?

The Apache webserver is an opensource and popular HTTP web server that continues to enjoy a massive market share in the hosting industry. It ships with loads of features including module enhancements, multi-protocol support, simplified configuration, and multi-language support to mention just a few.

How To Install Apache on Centos 8 ?

You just need to update your current system and use dnf package manager for installing using the following commands

$ sudo dnf update
$ sudo dnf install httpd


You can use rpm -qa <package name > for validation

Starting the Apache Server

sudo systemctl start httpd
sudo systemctl status httpd

From the output, the ‘active‘ status indicates that the Apache webserver is up and running.


From any browser , you can issue http://<Listening_IP_Address> or http://hostname

Setting Up Apache Virtual Hosts

A virtual host is a separate file that contains configurations that allow you to set up a separate domain from the default one. For this guide, we will set up a virtual host for the domain

The default virtual host is located at the /var/www/html directory. This works only for a single site. To create a separate virtual host for our domain, we will create another directory structure within the /var/www directory as shown.

sudo mkdir -p /var/www/

Next, edit the file permissions use the $USER environment variable as shown.

sudo chown -R $USER:$USER /var/www/

Also, adjust the permissions of the webroot directory as shown.

sudo chmod -R 755 /var/www

Next, create a sample index.html file using the following command.

sudo vi /var/www/
    <title>Welcome to!</title>
    <h1>virtual host is up and perfectly working!</h1>

Save and exit the configuration file.

Next, we need to create as the configuration file for the virtual host using the following

cd /etc/httpd/conf.d/
sudo vi

and add below :

<VirtualHost *:80>
    DocumentRoot /var/www/

Restart Apache for the changes to be applied.

$ sudo systemctl restart httpd

Last thing , you need to open any browser and issue


  1. I am trying to create virtual host and I following your post but I’m don’t succeeding to load my .war in browser, can you help me?


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook