Thursday, July 22, 2010

Setting Up Virtual Hosts on Apache for Linux

Dear All,

I was needed to set up a virtual host for an older LAMP application and the developers had worked with a different serer. So it used fixed directories and hardlinks. Sufferance. And the developers are long vanished from our horizon. So what to do to make it run again - Either edit the 40-50 pages and change the links or create a Virtual Host. I chose easy looking way of creating a virtual host.

How was I to know I've stepped into a mire and all that remained is sinking down in confusion. I went through 40-50 webpages for information and things got more confusing. So I went ahead and tried a number of solutions. I was about to give up when one combination worked. (Not perfectly though, I was stuck at not able to get host but it got solved within next 10 pages).


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


DocumentRoot "/var/www"
ServerName localhost

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

Please Remove the bloody double quotes in above lines; I couldn't make the page to display the proper text without them. Somehow the browser takes the virtualhost line as a tag.

I'll update this when I get solution to this. If you have anything put it in comments.

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

3. Now restart Apache server as:

sudo /etc/init.d/apache2  restart

4. Check if your localhost is alive and not messed up with at:

5. Check if your new site site1.local at:


Hope this helps you.

No comments:

Post a Comment