Setup Apache Virtual Hosts on CentOS 6.3

This shows how to setup virtual hosts on CentOS.

Configure apache

  • Configure the webserver
  • [root@webserver ~]# vim /etc/httpd/conf/httpd.conf

  • Uncomment “NameVirtualHost” (nearly at the end)
  • NameVirtualHost *:80

  • At the end, uncomment lines: (for the original host)
  • <VirtualHost *:80>
    DocumentRoot /var/www/html

Create a virtual domain

  • Create a config file for the new domain
  • [root@webserver ~]# cd /etc/httpd/conf.d/
    [root@webserver ~]# vim new.conf

    <VirtualHost *:80>
    DocumentRoot /var/www/html/new
    ErrorLog logs/
    CustomLog logs/ combined

Restart the webserver

  • [root@webserver ~]# service httpd restart

    Stopping httpd: [ OK ]
    Starting httpd: [ OK ]

Setup DNS / hosts file

  • Add domains to DNS
  • Add domains to hosts file for local use
  • You can add the hosts in your hosts file (/etc/hosts or C:\Windows\System32\drivers\etc\hosts)
    [root@webserver ~]# vim /etc/hosts
    Add the hosts

You have now setup a name-based virtual hosting.
Use your browser on both domains to test it.

Leave a Reply

}) _0- O-) ;) ;( :{ :o :Y :X :P :N :D :@ :? :9~ :) :(