The following steps will help you setup a virtual domain on apache 2.2 on Windows. Steps are very similar for OS X, only the location of the files will change.
In these steps I’ve used cowabunga.localhost as a test. The .localhost TLD is reserved for testing, so you can be guaranteed it won’t interfere with any real websites. This is the best practice to follow, if you create a virtual host of cowabunga.com, you will not be able to reach the real version of that site.
- Edit httpd.conf
- Uncomment the line Include conf/extra/httpd-vhosts.conf. Right after # Virtual hosts
- Add the following above # Virtual hosts (replace C:\www with the path to your web root). Close and save it when done.
<Directory "C:/www"> Order Deny,Allow Allow from all </Directory>
- We’ll setup the follow virtual host site.
- cowabunga (C:\www\cowabunga). We’ll access this in the browser as cowabunga.localhost.
- Edit httpd-vhosts.conf (located in apache root/conf/etc/)
- Add the following to the bottom of httpd-vhosts.conf. Close and save it when done.
<VirtualHost *:80> DocumentRoot "C:/www/cowabunga" ServerName cowagunga.localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/www/" ServerName localhost </VirtualHost>
- That’s it for apache configuration. It’s now ready to host the virtual domain. We just need to tell Windows to go to our virtual host, rather than looking up the DNS.
- Edit your “hosts” file. Available in one of the following places
- Windows 95, 98, ME: Windows directory
- NT, 2000, XP, 2003, Vista, 7: Windows folder\system32\drivers\etc\
- Mac OS X, iOS: /private/etc/hosts or /etc/hosts
- Add the following line to the end of hosts. Close and save it when done.
127.0.0.1 burgess.localhost 127.0.0.1 localhost
- Restart apache from the GUI or the command prompt using:
apache -w -n "Apache" -k restart