Sunday, 14 April 2013

Host multiple websites/domains on localhost.

Multiple websites/domains can be hosted on the local host/machine by tweaking httpd.conf file in apache.

Let's suppose, we want to host two sites website1.com and website2.com with root path as /www/website1 and /www/website2 respectively on local machine.

Add following lines at the end of httpd.conf file.

NameVirtualHost *:80



ServerAdmin webmaster@website1.com
DocumentRoot /www/website1
ServerName website1.com
ErrorLog logs/website1.com-error_log
CustomLog logs/website1.com-access_log common




ServerAdmin webmaster@website2.com
DocumentRoot /www/website2
ServerName website2.com
ErrorLog logs/website2.com-error_log
CustomLog logs/website2.com-access_log common


Now add following information in /etc/hosts file so that browser looks up for the domains on the local machine.

127.0.0.1 website1.com
127.0.0.1 website2.com


Restart apache.
Now all requests for website1 and website2 will be sent to the localhost.

For more info visit