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 pro.techbrown.com.

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


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.

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>
servername pro.techbrown.com
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 pro.techbrown.com

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 pro.techbrown.com

That’s all for now.

How to Schedule Cron Job on CentOS / RHEL

Previous article

How to Set Up NGINX Web Server on CentOS / RHEL

Next article

You may also like


Leave a reply

Your email address will not be published. Required fields are marked *

More in Linux