How to easily configure Virtual Hosts on your localhost

After spending 1 hour trying to figure out how to configure virtual hosts on my local projects installations in Windows 8.1 .. I finally got it working ; so I decided to write a quick tutorial about it 🙂

What we will create is  a virtual host under the name; “myproject”.  Change this to reflect your project alias name.

Edit hosts file

Go to

C:\Windows\System32\drivers\etc

Open “hosts” file using Notepad or so with admin privileges (You need to open notepad as admin: “run as admin”, this way you can save the changes inside the hosts file) and add the following to its end;

127.0.0.1 myproject

Save it and close.

Allow Virtual Hosts in httpd.conf

I’m using wampserver so to edit this apache configuration file, i left click on wamp tray icon and Apache -> httpd.conf. This opens the file in notepad.

Search for

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf

and comment out

Include conf/extra/httpd-vhosts.conf

This enables virtual hosts on Apache.

Add and configure virtual hosts individual projects

Now the only thing left to do is to add our projects to the httpd-vhosts.conf file located, depending on your setup in;

Apache2.4.4\conf\extra

In this file, some tutorials recommand adding localhost to the list of virtual hosts, like so;

<VirtualHost *:80>
DocumentRoot "d:/www"
ServerName localhost
ServerAlias localhost
<Directory "d:/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>

Then at the bottom of it, you add your project

<VirtualHost *:80>
DocumentRoot "d:/projects/myproject"
ServerName zaintest
<Directory "d:/projects/myproject">
AllowOverride All
Require local
</Directory>
</VirtualHost>

After you have done all the steps, restart wampserver for the configuration to be set.

That’s it you have  a running virtual host 🙂

7 thoughts on “How to easily configure Virtual Hosts on your localhost

  1. Psalms Psalms says:

    Nice tutorial. I will try it and give you update if it works. Thanks

  2. chris zipper says:

    it works! 🙂

  3. Rick Miranda says:

    So cool. I’ve done this before but needed a refresher. Plain simple and to the point. Awesome!

  4. Bravo says:

    Thanks man, you saved my ass

  5. arpan says:

    thanks alot buddy. 🙂

  6. Michal says:

    I can’t edit file “hosts”, Win10 tolds me, that I haven’t got authorization to edit and save something in ../drivers/etc/, but I am logged in Admin account. So, what can I do now? Another steps works fine. Thank you !

  7. admin says:

    You need to open notepad (or other program) as admin (run as admin), this way you can save the changes inside the hosts file.

Comments are closed.