Friday, June 13, 2014

[Apache] Setting up virtual hosts on Apache for Linux

Doing this by following official documentation is more confusing. 
I looked up many places and tried many combinations and finally foll. worked for me. 

Task: Keep your current apache localhost server alive and add a new site1.local server that has DocumentRoot at /home/vaibhav/mysite

1. Edit /etc/apache2/httpd.conf and add foll lines: 

NameVirtualHost 127.0.0.1

   DocumentRoot "/var/www"
   ServerName localhost

   DocumentRoot "/home/vaibhav/mysite"
   ServerName site1.local

2. Next edit /etc/hosts file and add foll line: 

127.0.0.1    site1.local

3. Now restart apache server as : 
sudo /etc/init.d/apache2 restart

4. Check out your virtual site as : 
http://site1.local/


No comments:

Post a Comment