Virtual hosts giving me fits

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Virtual hosts giving me fits

Postby Vcize » 20. May 2011 04:27

I keep all of my web files on a separate partition from my C drive, and would like to be able to access them from there (outside of my htdocs directory) with xampp.

After googling around a bit, it seems the best solution is virtual hosts (and that gives me the added bonus of having them set up as root directories for relative linking). However, setting up those virtual hosts is giving me fits and giving me 403 Access Denied errors.

For this example, let's just say my website is stored in P:/awesomesauce. Here's what I've done.

Added the following lines to httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
<Directory "C:/xampp/htdocs">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "P:\awesomesauce"
ServerName awesomesauce.localhost
<Directory "P:\awesomesauce">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


Added the following to my hosts file...
# xampp virtual hosts
127.0.0.1 localhost awesomesauce.localhost


However, when I then go to awesomesauce.localhost in my browser I get the following...
Access forbidden!

You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.

If you think this is a server error, please contact the webmaster.
Error 403
awesomesauce.localhost
5/19/2011 11:26:23 PM
Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1


Googling has led me to lots of discussions about it, but no solution that I could get working.

Help!
Last edited by Vcize on 20. May 2011 16:01, edited 1 time in total.
Vcize
 
Posts: 4
Joined: 20. May 2011 04:13

Re: Virtual hosts giving me fits

Postby Sharley » 20. May 2011 09:06

Vcize wrote:However, when I then go to music.localhost in my browser I get the following...
But you don't have a vhost for this ServerName music.localhost, so how can Apache find it?.

It would be able to find http://awesomesauce.localhost and will give you what ever index page you have in that related Directory.

Code: Select all
# xampp virtual hosts
127.0.0.1 localhost
127.0.0.1 awesomesauce.localhost
127.0.0.1 music.localhost
Keeps the host file unambiguous and easier to read especially if you grow it - preferable to having everything on the one line.

So if you add a vhost also for music.localhost then you should not get any errors.
Code: Select all
<VirtualHost *:80>
DocumentRoot "P:\awesomesauce\music"
ServerName music.localhost
<Directory "P:\awesomesauce\music">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Just add this after your other vhosts and then http://music.localhost should be found if you also have an index file in the P:\awesomesauce\music directory.
Get the idea?

Also a good idea when ever you get server errors is to check out the \xampp\apache\logs\error.log file for more detailed clues from the server not a canned error message that the browser gives you.


Tip:
Instead of Google, try searching this English forum for vhost or virtualhost as you will find some very useful examples - you can use my name Sharley in the Author field for reducing the amount of results returned if you prefer.

Good luck. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Virtual hosts giving me fits

Postby Vcize » 20. May 2011 16:01

Sharley wrote:
Vcize wrote:However, when I then go to music.localhost in my browser I get the following...
But you don't have a vhost for this ServerName music.localhost, so how can Apache find it?.

It would be able to find http://awesomesauce.localhost and will give you what ever index page you have in that related Directory.


Ack, sorry, that was a typo in my post as that was the second site I tried it out on.

I'm typing http://awesomesauce.localhost into my browser and getting the error, not music.localhost.
Vcize
 
Posts: 4
Joined: 20. May 2011 04:13

Re: Virtual hosts giving me fits

Postby Sharley » 21. May 2011 02:43

You don't have an index file in the awesomesauce folder.

Copy and paste the index.html file from the C:\xampp\htdocs folder into the awesomesauce folder and then try http://awesomesauce.localhost again or http://awesomesauce.localhost/index.html and you should see It works! returned to your browser.

If that works then delete the index.html file and replace with an index file for your own web site.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Virtual hosts giving me fits

Postby Vcize » 22. May 2011 02:10

Sharley wrote:You don't have an index file in the awesomesauce folder.

Copy and paste the index.html file from the C:\xampp\htdocs folder into the awesomesauce folder and then try http://awesomesauce.localhost again or http://awesomesauce.localhost/index.html and you should see It works! returned to your browser.

If that works then delete the index.html file and replace with an index file for your own web site.


There was an index.php file in there. The sites I'm trying to test are forums, wordpress sites, etc. If I have a DB set up those should work locally, right?

Also, just for kicks I tried putting the index.html file from the htdocs folder (the "It Works!" one) in there and removing the index.php file that was already there, and I still got the access denied error.
Vcize
 
Posts: 4
Joined: 20. May 2011 04:13

Re: Virtual hosts giving me fits

Postby Sharley » 22. May 2011 03:06

Sharley wrote:Also a good idea when ever you get server errors is to check out the \xampp\apache\logs\error.log file for more detailed clues from the server not a canned error message that the browser gives you.
So what does it tell you about your issue?

Make sure you have created the folder in P:\ with the exact name you have in your vhosts as I was able to replicate your issues exactly and get the 403 error with the following:

awesomesource instead of awesomesauce
No index file

Once the above was corrected the 'It works' page displayed.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 128 guests