Connect with us

Hi, what are you looking for?


How to Configure Apache Virtual Hosts on CentOS 8 / RHEL 8

In this tutorial we are configuring Apache Virtual Hosts on CentOS 8 / RHEL 8. The Virtual Hosting is used to host multiple domains or websites on a single Apache installation. Virtual hosting can be either Name-based or IP-based. It is generally used in shared hosting environment.Virtual Hosts are configured in “Virtual Host” block in the main configuration file of Apache or separate .conf file in /etc/httpd/conf.d/ directory.In this tutorial the virtual host is

Step-1 : Check whether the httpd packages is install by default or not

[root@techbrown~]# rpm -q httpd

Step-2 : Install the httpd package using DNF package manager

[root@techbrown~]# dnf install httpd* -y

Step-3 : As soon as installation completes start the services of httpd

[root@techbrown~]# systemctl start httpd

Step-4 : Enable the services of httpd so that it will survive during boot

[root@techbrown~]# systemctl enable httpd

It will show given output

ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-'

Step-5 : Add the service http from the firewalld firewall for communicating with httpd 

[root@techbrown~]# firewall-cmd --permanent --add-service=http

It will show given output


Step-6 : When done reload the firewall to activate the new rules

[root@techbrown~]# firewall-cmd --reload

It will show the given output

Advertisement. Scroll to continue reading.

Step-7 : Create a virtual directory for set up virtual web server

In this tutorial we create the folder  under default root folder i,e  /var/www and users can change that to be whatever folder they want. Virtual Hosts needs to have separate Document Root directory.

[root@techbrown~]# mkdir /var/www/virtual

Step-8 : Change the Context of the virtual directory to http context

The /var/www is a default root directory for web server. because of that http context automatically assigned.

[root@techbrown~]# restorecon -vvFR /var/www/virtual

Step-9 : Change Current Working Directory to the /var/www/virtual

[root@techbrown~]# cd /var/www/virtual

Step-10 : Create a .html file

Create a .html file and enter the contents of web site and here virtual.html is our html file.

[root@techbrown virtual]# vim virtual.html

In this file user have to write and save their contents. Contents written in this file will appear in the website.

Advertisement. Scroll to continue reading.

Step-11 : Change Current Working Directory to /etc/httpd/conf.d

[root@techbrown virtual]# cd /etc/httpd/conf.d

Step-12 : Create a configuration file here

For ex. we create virtual.conf,

[root@techbrown conf.d]# vim virtual.conf

<virtualhost *:80>
documentroot /var/www/virtual
<directory /var/www/virtual>
Require all granted

Step-13 : Check the Configuration file

If Some error occurred they show the problem having configured line.

[root@techbrown~]# httpd -t

Step-14 :Connect the host name to IP address.

[root@techbrown~]# vim /etc/hosts

Step-15 : When completed, restart the httpd services to make changes in the effect

[root@techbrown conf.d]# systemctl restart httpd

Step-16 : Reload the firewalld to flush the old firewall rules and implement the new one

[root@techbrown conf.d]# firewall-cmd --reload

Step-17 : Check whether the your server is running or not with the allowed domains, Using browser

[root@techbrown conf.d]# firefox

Conclusion : Now you have successfully configure a Apache virtual web server and now you are ready to launch a website on your domain name with ease. You are now learned how to run various domains into a single web server using Apache web server. If you have any issues related to this tutorial feel free to use the comment section below.

Advertisement. Scroll to continue reading.

You May Also Like


How to auto upgrade JioFi firmware for JioFi 2 / JioFi 3 / JioFi 4 / JioFi 5 / JioFi 6 and other JioFi...


Internet is the most important public network for connecting to the WEB. For internet connection requirement the ISP is required as well as it...


How to download and install the Mobile Intel 4 Series Express Chipset Graphics Drivers for Windows 10.  Windows 10 is the one of the...


How to Install and Configure PCSX2 on Windows 10. The Windows 10 is the most recommended operating system for the Games. In stream platform...