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).



SO FOLL. IS THE PROCEDURE:

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

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
DocumentRoot "/var/www"
ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1>
DocumentRoot "/home/vaibhav/mysite"
ServerName site1.local
</VirtualHost>

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.: 


127.0.0.1 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:

http://127.0.0.1/


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


http://site1.local/



Hope this helps you.

No comments:

Post a Comment