Virtual Host question

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

Virtual Host question

Postby attilio87 » 11. April 2011 19:37

At the moment I've set up a few virtual hosts. However for each one I have to modify window's hosts file. I was wondering if there was possibly a way to get around. I run xampp off of my flash drive so that I can easily work on websites from both my PC and laptop. Unfortunately I have to edit the windows hosts file on both.

What I would like to do is set up a virtual host so that when I visit localhost/mysite then the mysite directory would be the document root. If I go to localhost/anothersite then the anothersite directory would be the document root.
attilio87
 
Posts: 5
Joined: 11. April 2011 19:33

Re: Virtual Host question

Postby Sharley » 12. April 2011 01:36

So what happens when you don't add to the hosts file and try to access a vhost on your portable device?
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 Host question

Postby attilio87 » 12. April 2011 01:41

The site would run normally.

Basically what I want is for the virtual host's folder to act like the document root. The reason is because I use the php variable $_SERVER['DOCUMENT_ROOT'] often, so for me it would be easier if each website would have its own document root. I know virtual host's can do this, but its a pain to keep updating the hosts file every time I create a new website. If I really only did work on my PC and laptop it wouldn't be so bad, but the major reason I use a portable device is so that I can take it to another computer and easily run any website.
attilio87
 
Posts: 5
Joined: 11. April 2011 19:33

Re: Virtual Host question

Postby Sharley » 12. April 2011 02:34

What version of XAMPP?

Please can you paste here you complete httpd-vhosts.conf file so I can see how you have configured it as I can't work blind folded. :)

I may well then be able to make some suggestions.
Thanks.
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 Host question

Postby attilio87 » 12. April 2011 02:37

This is basically it. The second virtual host (stoa) is just copied over and over for all the other virtual hosts I have. Obviously for each of the other ones I change the folder, name, alias, etc. so its appropriate for that one.

NameVirtualHost *:80

<VirtualHost *:80>
ServerAdmin postmaster@localhost
DocumentRoot "/xampplite/htdocs"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost.log"
CustomLog "logs/localhost.log" combined
</VirtualHost>

<VirtualHost *:80>
ServerAdmin postmaster@stoa.localhost
DocumentRoot "/xampplite/htdocs/stoa"
ServerName stoa.localhost
ServerAlias stoa.localhost
ErrorLog "logs/stoa.log"
CustomLog "logs/stoa.log" combined
</VirtualHost>
attilio87
 
Posts: 5
Joined: 11. April 2011 19:33

Re: Virtual Host question

Postby Sharley » 12. April 2011 02:47

So when you put the USB device into another PC that does not have an XAMPP installation or an entry in the Windows hosts file, what happens when you type http://stoa.localhost in the browser?

What happens when you put the USB into your current PC that has XAMPP installed but is not running and you have temporarily deleted the vhost entries like 127.0.0.1 stoa_localhost and you type http://stoa.localhost in the browser?

Please give full details even error.log file entries if they exist as I can't see what you are doing or what you see on your monitor - you have to be my eyes.

I am currently setting up a USB to test what you pasted here but I can see a couple of issues already that I will paste back after some testing and receiving your answers from the above questions.

I can only test on my single PC as I do not have another PC to test the USB drive with..
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 Host question

Postby attilio87 » 12. April 2011 02:54

XAMPP runs off of my flash drive. So when I connect it to my PC I just click start for XAMPP and it starts right up. For all of the virtual hosts, my windows hosts file has the appropriate entry. So using stoa.localhost has an example, my windows hosts file would have:

127.0.0.1 localhost
127.0.0.1 stoa.localhost

So when I visit stoa.localhost the website opens up. The stoa folder is the document root. The site works perfectly. Now if I were to take out the 127.0.0.1 stoa.localhost entry from the windows hosts file it'll come up as the website cannot be found, which is what its supposed to do. If I do localhost/stoa, the website will load but anything that has to do with $_SERVER['DOCUMENT_ROOT'] won't work. Basically because it looks in the htdocs folder.

My XAMPP is setup in such a way that the htdocs folder is the primary document root. Each virtual host has its own document root (in this example that would be stoa). What I want to be able to do is go to localhost/stoa and have the stoa folder be the document root for that. Then I want to be able to go to localhost/abc123 and have the abc123 folder the the document root for that.
attilio87
 
Posts: 5
Joined: 11. April 2011 19:33

Re: Virtual Host question

Postby Sharley » 12. April 2011 07:33

Sorry for the delay, got side tracked as usual.
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerAdmin postmaster@localhost
DocumentRoot "/xampplite/htdocs"
ServerName localhost
ErrorLog "logs/localhost.log"
CustomLog "logs/localhost.log" combined
</VirtualHost>

<VirtualHost *:80>
ServerAdmin postmaster@stoa.localhost
DocumentRoot "/xampplite/htdocs/stoa"
ServerName stoa
ErrorLog "logs/stoa.log"
CustomLog "logs/stoa.log" combined
</VirtualHost>
Drop the Alias as you have duplicated the ServerName as the Alias and no need for stoa.localhost unless you type that name in your browser, http://stoa.localhost just use stoa then you can simply use http://stoa and no possible localhost confusion issues.

These 2 links may give you some ideas.
http://www.webmasterworld.com/forum88/12512.htm
...and another similar solution here:
http://jbenner.net/blog/quick-tip-get-p ... host-alias

I also found Google to have a plethora of related solutions but they do require you to use perhaps various keywords and much reading before the possible solution pops out. :)
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 Host question

Postby attilio87 » 12. April 2011 14:07

Thank you, I'll look into it.
attilio87
 
Posts: 5
Joined: 11. April 2011 19:33


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 117 guests