1

-------

Configure Name based Virtual Hosting on CentOS 7 step by step

Step: 1. To install apache

# yum install httpd -y

Installed:

httpd.x86_64 0:2.4.6-45.el7.centos.4

Dependency Installed:

apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7

httpd-tools.x86_64 0:2.4.6-45.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7

Complete!

[root@p /]# systemctl start httpd

[root@p /]# systemctl enable httpd

Step:2 To Create the directory for Virtual Host name

[root@proxy html]# mkdir -p /var/www/html/www.worldcm.net

[root@proxy html]# mkdir -p /var/www/html/www.faruq.com

[root@proxy html]# mkdir -p /var/www/html/www.arif.net

[root@proxy html]# ls

http://www.arif.net http://www.faruq.com http://www.worldcm.net

# echo "Welcome to My arif.net Website" > /var/www/html/www.arif.net/index.html

Step:3 To create index.html as per hosting namewise like, Similarly, to create worldcm and faruq

<html>

<head>

<title>www.arif.net</title>

</head>

<body>

<h1>The arif.net virtual host is working!</h1>

</body>

</html>

Step:4 To setup ownership and permissions

[root@proxy /]# chown -R apache:apache /var/www/html/www.arif.net/

[root@proxy /]# chown -R apache:apache /var/www/html/www.faruq.com/

[root@proxy /]# chown -R apache:apache /var/www/html/www.worldcm.net/

[root@proxy /]# chmod -R 755 /var/www/html

Step:5 To setup Name based virtual hosting on apache

[root@proxy conf.d]# pwd

/etc/httpd/conf.d

[root@proxy conf.d]#  vi httpd-vhost.conf

<VirtualHost *:80>

ServerName http://www.arif.net

ServerAlias arif.net

DocumentRoot /var/www/html/www.arif.net

ErrorLog /var/www/html/www.arif.net/error.log

CustomLog /var/www/html/www.arif.net/access.log combined

</VirtualHost>

<VirtualHost *:80>

ServerName http://www.faruq.com

ServerAlias faruq.com

DocumentRoot /var/www/html/www.faruq.com

ErrorLog /var/www/html/www.faruq.com/error.log

CustomLog /var/www/html/www.faruq.com/access.log combined

</VirtualHost>

<VirtualHost *:80>

ServerName http://www.worldcm.net

ServerAlias worldcm.net

DocumentRoot /var/www/html/www.worldcm.net

ErrorLog /var/www/html/www.worldcm.net/error.log

CustomLog /var/www/html/www.worldcm.net/access.log combined

</VirtualHost>

[root@proxy conf.d]# apachectl configtest

Syntax OK

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

Step:6 To add the virtual hosts for DNS

[root@proxy conf.d]#   vi /etc/hosts

127.0.0.1 localhost.localdomain localhost

::1 localhost6.localdomain6 localhost6

10.100.100.123 http://www.arif.net

10.100.100.123 http://www.faruq.com

10.100.100.123 http://www.worldcm.net

Step:7 Go to browser for Test

http://www.arif.net

Result : The arif.net virtual host is working!

http://www.faruq.com

Result : The faruq.com virtual host is working!

http://www.worldcm.net

--------