Set up an apache virtual host in 30 seconds for windows

September 14, 2005

If you're a developer working with apache and have multiple folders in your web root for clients project you really need to make use of virtual hosts. A virtual host allows you to type in clienta.localhost.com and map that to C:\inetpub\wwwroot\clients\clienta and the same with clientB.localhost.com and map that to C:\inetpub\wwwroot\clients\old\clientB

in your browser you can just type in clientB.localhost.com and you're all set. So here's how to do it in 30 seconds on windows

First thing we need to do is edit our hosts file to tell it when you type in that address where to go so open up in notepad:
C:\Windows\system32\drivers\etc\hosts (may be different on your system)

add these lines and save the file
127.0.0.1 clienta.localhost
127.0.0.1 clientB.localhost

now open up the httpd.conf file in C:\Program Files\Apache Group\conf\httpd.conf
and find the VIRTUAL HOST section. (search for "VirtualHost example:")

add add these lines
NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
DocumentRoot "C:\inetpub\wwwroot\clients\clienta"
ServerName clientB.localhost
</VirtualHost>

<VirtualHost 127.0.0.1>
DocumentRoot "C:\inetpub\wwwroot\clients\old\clientB"
ServerName clientB.localhost
</VirtualHost>

save that file and restart apache, now open up your browser of choice and type in clientB.localhost.com and boom you're virtual.

Comments

RSS feed for comments on this post.

  1. great tip mate says:
    March 13, 2010 @ 05:19 — Reply

    Comment pending moderation

Leave a Comment

Line and paragraph breaks automatic, HTML allowed: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <code> <em> <i> <strike> <strong>

Comments disabled due to spammers being losers that lead sad lives.