I'm trying to set up virtual hosts for local development and can't seem to get it working.

I have this in my httpd.conf:

NameVirtualHost *

<VirtualHost *>
 ServerName localhost
 DocumentRoot C:/Users/Elliot/dev/UniServer/www
</VirtualHost>

<VirtualHost *>
 ServerName drupal.dev
 DocumentRoot C:/Users/Elliot/dev/UniServer/www/drupal.dev/httpdocs
</VirtualHost>

and this in C:\Windows\System32\drivers\etc\hosts:

127.0.0.1       localhost
127.0.0.1       drupal.dev

http://localhost resolves OK, http://drupal.dev/ does not.

Any ideas welcomed...


Edit: I'm pretty sure that my hosts file is the underlying problem and that any edits are being ignored.

Oddly, I can edit, save and delete it without elevated permissions, which should not be the case on Windows >= Vista.

Am working through 'What can cause a DNS lookup to ignore a hosts file entry?', 'HOSTS file being ignored' and 'Problem with the hosts file in Windows XP (as a new user I can't post links).


Edit: in my case, stopping the DNS Client service resolved the issue....


Edit: ...but only very briefly.

link|improve this question
Looks good to me.Reboot your machine :) – systempuntoout Apr 26 '10 at 19:14
Done, no change. – e100 Apr 28 '10 at 12:20
feedback

migrated from stackoverflow.com Apr 27 '10 at 0:05

This question came from our site for professional and enthusiast programmers.

5 Answers

up vote 0 down vote accepted

Do a ping of drupal.dev and make sure its resolving to your machine. Also, try setting the documentRoot to the same as the one above (C:/Users/Elliot/dev/UniServer/www/) just in case it's a premissions issue.

link|improve this answer
Hmm, ping fails. Any ideas? – e100 Apr 28 '10 at 7:01
If a ping fails- it means your host entry is not working properly- I would check this. – AliGibbs Apr 28 '10 at 11:44
OK, pretty sure it's a hosts problem, which is a different question. Have edited question to reflect this. – e100 Apr 28 '10 at 13:57
feedback

Look at the example here:

http://www.cyberciti.biz/faq/apache-name-based-virtualhost-example/

Set the IP address for the NameVirtualHost and then replace the * for each VirtualHost with the qualified name (localhost for the first and drupal.dev for the second).

link|improve this answer
Make sure you add a ServerAlias as well for drupal.dev to: ServerAlias *drupal.dev – Jon Apr 26 '10 at 19:14
Thanks but as per AliGibbs' answer, it looks like the underlying issue issue is with the hosts file. – e100 Apr 28 '10 at 12:22
feedback

Try putting drupal.dev on the same line as localhost in your hosts file, e.g:

127.0.0.1   localhost drupal.dev
link|improve this answer
feedback

make sure, that vhost module is loaded.

Best regards,

Martin Kudlacek

link|improve this answer
feedback

Do you have this entry :

NameVirtualHost *

It allows you to enable the vHosts

link|improve this answer
Yes, in my question, it's the first line I quote from httpd.conf – e100 Apr 28 '10 at 14:24
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.