Saturday, November 21, 2009

Setting up a local Virtual Host using WAMP/Apache

Setting up a virtual host will allow you to essentially run an exact copy of your site locally.  You'll need to decide on a local domain name.  My standard is to only maintain the primary name.  So for instance if the site is then I will use http://domain/ for the local copy.  Some people decide to use http://domain.loc/.

Once you've decided, open C:\Windows\System32\drivers\etc and open the hosts file.

It should look like this when opened:       localhost
::1             localhost

Add a new line       localhost       domain
::1             localhost

Replace "domain" with "domain.loc" if you want.

Next you're going to need to locate your Apache installation. In WAMP, you're going to need to open C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf and add the line:

    ServerAdmin webmaster@localhost
    DocumentRoot "c:/wamp/www/domain"
    ServerName domain
    ErrorLog "logs/domain.log"
    CustomLog "logs/domain.log" common
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Allow,Deny
        Allow from all
        Allow from


NameVirtualHost *:80

    DocumentRoot "c:/wamp/www"
    ServerName localhost

If you're using .loc, all you should have to do is add .loc to the ServerName, NOT to the paths defining the location to load.

No comments:

Post a Comment