Page 1 of 1

Virtual hosts doesn't work when internet is offline

PostPosted: 03. October 2011 19:28
by Darek
What I'm using:

XAMPP ver. 1.6.7
Windowx Vista Home


My configuration:

I have configured windows hosts like this:

Code: Select all
127.0.0.1 localhost
127.0.0.1 test.local


and xampp (apache) virtual hosts like this:

Code: Select all
<VirtualHost *:80>
  ServerName test.local
  DocumentRoot "D:\xampp\htdocs\test"

  <Directory "D:\xampp\htdocs\test">
    AllowOverride All
  </Directory>
</VirtualHost>


The problem is:

When I have internet connection I can access http://localhost/phpmyadmin AND http://test.local
When I'm offline, I can only access http://localhost/phpmyadmin BUT NOT http://test.local

How do I solve this, and why virtual hosts require internet connection to work?

Re: Virtual hosts doesn't work when internet is offline

PostPosted: 03. October 2011 19:52
by WilliL
is in the beginning of your "httpd-vhosts.conf" the following command?
Code: Select all
NameVirtualHost 127.0.0.1:80


If not please have a look to http://httpd.apache.org/docs/2.2/en/vhosts/

Re: Virtual hosts doesn't work when internet is offline

PostPosted: 03. October 2011 20:07
by Darek
When I added
Code: Select all
NameVirtualHost 127.0.0.1:80

I can't access localhost at all

Code: Select all
NameVirtualHost *:80

This code above works, but it seems that this line doesn't change anything from my previous configuration.

Re: Virtual hosts doesn't work when internet is offline

PostPosted: 03. October 2011 20:32
by Sharley
We require your XAMPP version and your Windows Version to provide the correct version support.
viewtopic.php?f=16&t=48331
viewtopic.php?f=16&t=32670

Thanks.

Re: Virtual hosts doesn't work when internet is offline

PostPosted: 03. October 2011 20:46
by Darek
Sorry for that, I already updated my first post providing XAMPP and Windows version.

Also I noticed interesting thing:

1. With internet connection I can ping test.local
2. Without internet connection, when I try to ping test.local I get this message: "Ping request could not find host test.local. Please check the name and try again."

Re: Virtual hosts doesn't work when internet is offline

PostPosted: 03. October 2011 21:00
by Sharley
I see a very old XAMPP version is there any reason not to use the latest version?

Are you logged into Vista as an Administrator?

Try this configuration in the httpd-vhosts.conf file in the extra folder as it seems you have not included all required entries - you can copy and paste it but first make a backup copy of the original:
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:/xampp/htdocs"
</VirtualHost>

<VirtualHost *:80>
ServerName test.local
DocumentRoot "D:/xampp/htdocs/test"
<Directory "D:/xampp/htdocs/test" >
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Save the file and restart Apache.

It has been mentioned here that nesting a vhost is not recommended ie. using the htdocs folder to add another folder that is a VirtualHosts but it should work if all the configurations are correct.

A virtual host can be setup to access any folder on your PC.

Good luck. :)

Re: Virtual hosts doesn't work when internet is offline

PostPosted: 03. October 2011 21:38
by Darek
Sharley wrote:I see a very old XAMPP version is there any reason not to use the latest version?

The only reason is that our client's hosting have old version of PHP and MySQL installed. We found that there's few differences between old and new version, and we needed to test the whole system on our computers. That's why we choose old XAMPP version.

Sharley wrote:Are you logged into Vista as an Administrator?

Of course.

Sharley wrote:Try this configuration in the httpd-vhosts.conf(...)

I tried it, but the problem is still there. Now I think it may not be apache problem, but something with Windows itself.


Solution: As I write this post, I found solution to my problem. It was in fact Windows problem. It appears that if "DNS Client" service is turned off, Windows doesn't use hosts file when computer is offline. Maybe this will help someone in future, as I was searching for solution to this problem, found few similar questions, but not a single solution.

Re: Virtual hosts doesn't work when internet is offline

PostPosted: 03. October 2011 21:55
by Sharley
Thanks for the feed back. 8)

Best wishes. :)

Re: Virtual hosts doesn't work when internet is offline

PostPosted: 05. October 2011 16:12
by angelace
Solution: As I write this post, I found solution to my problem. It was in fact Windows problem. It appears that if "DNS Client" service is turned off, Windows doesn't use hosts file when computer is offline. Maybe this will help someone in future, as I was searching for solution to this problem, found few similar questions, but not a single solution.


... It did help someone else (today) . Thanks for the timely post... back to the grind - Angela