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 *>
 ServerName drupal.dev
 DocumentRoot C:/Users/Elliot/dev/UniServer/www/drupal.dev/httpdocs

and this in C:\Windows\System32\drivers\etc\hosts:       localhost       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.

  • Looks good to me.Reboot your machine :) – systempuntoout Apr 26 '10 at 19:14
  • Done, no change. – e100 Apr 28 '10 at 12:20

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.

  • Hmm, ping fails. Any ideas? – e100 Apr 28 '10 at 7:01
  • 1
    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

Look at the example here:


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).

  • 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

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

Do you have this entry :

NameVirtualHost *

It allows you to enable the vHosts

  • Yes, in my question, it's the first line I quote from httpd.conf – e100 Apr 28 '10 at 14:24

Just another example how I got it working with Uniserver. My pseudo domain is "memelpower.lc" and the root you can see below.

In C:\uniserver\core\apache2\conf\httpd.conf you add this to the end of the file:

NameVirtualHost *

<VirtualHost *:80>
    ServerAdmin admin@memelpower.lc
    DocumentRoot "C:/uniserver/www/memelpower/public/"
    ServerName memelpower.lc
    ServerAlias memelpower.lc
    ErrorLog "C:/uniserver/www/memelpower/public/error_log"
    CustomLog "C:/uniserver/www/memelpower/public/access_log" common

Then you C:\Windows\System32\drivers\etc\hosts you add this line in the end: localhost memelpower.lc

Restart Apache and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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