Page 1 of 1

Virtual Hosts on Apache

PostPosted: 17. August 2009 17:36
by ChrisNY
Hi;

I have my localhost, with the document root say at: "E:/app/SymLink_DoNotDelete/". Within that directory, I have several subdirectories, including E:/app/SymLink_DoNotDelete/overheard. If I just entered "http://localhost" in my browser, I got the localhost directory listing. If I typed http://localhost/overheard, I got the webpage in the "overheard" directory.

But I wanted to be able to access the "overheard" site by just entering "http://overheard", for various obvious reasons. So I tried virtual hosts.

I've got virtual hosts working (sort of) on my local development version of Apache -- that is, when I type in the URL http://overheard, I get the appropriate webpage.

However, now http://localhost also gives the contents of the "overheard" subdirectory, so I did something wrong. Here is the entry I made in my httpd.conf file, at the end:

Code: Select all
<VirtualHost overheard>
    ServerName   overheard
    DocumentRoot "E:/app/SymLink_DoNotDelete/overheard/public"
</VirtualHost>


Can anyone tell me how to get my original localhost back (to my document root), while still keeping my virtual host "Overheard" pointing to the overheard directory?

Thanks.

Re: Virtual Hosts on Apache

PostPosted: 17. August 2009 18:05
by Wiedmann
Can anyone tell me how to get my original localhost back (to my document root), while still keeping my virtual host "Overheard" pointing to the overheard directory?

Add a virtual host for "localhost".

Re: Virtual Hosts on Apache

PostPosted: 17. August 2009 19:28
by ChrisNY
Hi, thanks; that seemed like the perfect answer, but when I tried it, then everything (both localhost & overheard) resolved to the original localhost path. Especially odd since I put the Localhost definition before the overheard definition, so you would think if one overwrote the other, it would be the last, overheard. Could I have made some syntax or argument error in the virtual host declaration? This is what I put at the end of my httpd.conf file:

Code: Select all
<VirtualHost localhost>
    ServerName   localhost
    DocumentRoot "E:/app/SymLink_DoNotDelete"
</VirtualHost>

<VirtualHost overheard>
    ServerName   overheard
    DocumentRoot "E:/app/SymLink_DoNotDelete/overheard/public"
</VirtualHost>


Thanks again for your suggestion; it should have worked...

Re: Virtual Hosts on Apache

PostPosted: 17. August 2009 20:22
by Wiedmann
You want use namebased virtual hosts (all hostnames have the same ip)?

Re: Virtual Hosts on Apache

PostPosted: 17. August 2009 22:17
by Izzy
First remove the virtualhost entries from the httpd.conf file then save the file and try and restart Apache to make sure the httpd.conf file is syntactically correct.

Next use \xampp\apache\conf\extra\httpd-vhost.conf file to add your entries for example:
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName   localhost
    DocumentRoot "E:/app/SymLink_DoNotDelete"
</VirtualHost>

<VirtualHost *:80>
    ServerName   overheard
    DocumentRoot "E:/app/SymLink_DoNotDelete/overheard/public"
</VirtualHost>
Save the file after editing.

Next open \Windows\system32\drivers\etc\hosts file by dragging it into your text editor (in Vista right click on the text editor and select to run as administrator then Open the above file).

make sure your have these 2 entries first and if not then add them:
Code: Select all
127.0.0.1 localhost
127.0.0.1 overheard
Save the file and now restart Apache and see if that works for you.

BTW always a good idea to keep clearing your browser's cache when working at localhost level or you may be served a cached page instead of a newly edited page.