Thursday, 7 March 2013

thumbnail

How to do virtual hosting and website in CentOS 6

How to do virtual hosting in CentOS 6 

Virtual-Hosting:-

With the help of virtual-hosting you can create multiple website and  point it to single ip address.

1.Open the terminal and type.

# vim /etc/httpd/conf/httpd.conf

uncommend the line no :-990
NameVirtualHost *:80






2. Copy the last tag <virtualhost> starting from line 1003 to 1009

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>



3. Paste it at the end. and edit it.

<VirtualHost *:80>
   DocumentRoot /var/www/html/virtualhost
   ServerName www.virtual.host
   ServerAdmin webmaster@virtual.host
   ErrorLog logs/virtual.host-error_log
   CustomLog logs/virtual.host-access_log combined
</VirtualHost>

After that save and exit the file.



4. Then we have to create a directory inside /var/www/html/virtualhost so that its contain should remian separately from the default or other website.

# mkdir /var/www/html/virtualhost

5. Create one index.html file so that we can test it.

# cd /var/www/html/virtualhost
# vim index.html

<html>
<body>

Hello world:-

</body>
</html>

After editing save and exit.

6. Now we have to add an website name entry in /etc/hosts file 




Add the ip address and website name like this

192.168.100.159 www.virtualhost.com

Save and exit the file.

7. Restart the httpd service like this.

# service httpd restart
Stopping httpd: 
[  OK  ]

Starting httpd: 

[  OK  ]


8. Now open the browser and type the website name.


As you can see "Hello world " appeared as per our index.html file.
You can put whatever your website content in the /var/www/html/virtualhost folder.

Note:- You can create as many as virtual hosting and website but remember to create separate directory and add the website in /etc/hosts file.

That's it enjoy virtual hosting in CentOS-6






Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments