Home > Installation Guides > Virtual Host Setup
In this document we describe the process of setting up a Virtual Host on a machine. The most common use of this technique is to use FormBoss on a local machine. We could do this because our live domain name doesn't currently have a server, because we are transferring domains, and several other reasons. The end result in each case though is we run FormBoss locally instead of on a web server.
The first step as you would expect is making sure we already have a proper local web server stack already running, of which Zend Server CE, XAMPP, MAMP, and several other installer packages make quite simple.
With that part done, on with the instructions:
Step 1 - Configure The Hosts File
First we need to need to create a hosts entry for your domain to match the one it is licensed for. This is a simple process of Adding a hosts entry to your hosts file. On most modern Windows systems (64 bit and others) this file is located at:
C:\Windows\System32\drivers\etc
On Vista/Win 7 machines we need to—and should—make a copy of this file to a ‘safe’ location, that is, one where you have write access, such as your Documents folder. We edit the copied version on our writeable location, then overwrite the one in the c:\windows location. That way you always have a backup!
On Mac and other *NIX variants the location is generally:
/ect/hosts.
The process of adding the hosts entry is basically the same for both OS’s, in that the change we make is to add a localhost entry that binds to our ‘fake’ web address. For example, if I wanted to bind to www.formboss.net I would open the copied hosts file and add:
(you’ll notice I use lots of vhosts!)
The first column, the 127.0.0.1, is a special IP address called our localhost loopback address, and means the request maps to this machine as opposed to somwhere else on the local network or Internet. The second column is the hostname we want to map to that ip address. When set as shown above, any request coming from a web browser (or any other local network interface) on our local machine will be handled by our local machine. This is what we mean by intercept. Instead of the request to www.formboss.net being handled by a DNS server, it's handled in the hosts file and mapped to 127.0.0.1, which is the local address of the machine. Because our local Apache install is listening to that address for http requests, we effectively serve that site when typed into a web browser.
More info on the hosts file on windows and general host file information.
Step 2 - Configuring Apache
The second (and last step) is to tell Apache to serve that localhost request as defined in the hosts file. We do this by adding a vhost entry to an Apache config file, which is generally a separate entity from the base httpd.conf file called: vhosts.conf. Of course it should be said that this setup, that is, if we define the vhost in httpd.conf or in a different file called vhosts.conf, varies depending on system and package.
For example, Debian Linux distributions (like Ubuntu) generally have a separate file and folder structure for defining virtual hosts. This is done in /etc/apache2/sites-availible and etc/apache2/sites-enabled. The trick is that /sites-availible contains the virtual host definitions for each site, but only when a symlink of these files is placed in /sites-enabled do they get served by Apache.
This is a pretty darn elegant setup, and highlights just how modular and customizable Apache is. It is however, a bit more involved than what Windows user have to deal with.
Thus, for a stand-alone Apache for Windows install this file is typically located at:
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf
On Linux/Mac OS this path varies as described above; please contact me for more details if you cannot find it.
Of course if you have XAMPP, Zend Server CE, or some other bundled Stack, this file should be easy to find, as it will be located within the same directory as all other files for that stack. This is true for Windows and Mac/Linux etc.
When we find the file, using my same www.formboss.net example, I would scroll to the bottom of the vhosts config file and add:
<VirtualHost *:80>
ServerAdmin email@formboss.net
DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/patch"
ServerName www.formboss.net
</VirtualHost>
This tells apache to take any request from my local browser to www.formboss.net and serve the content from DocumentRoot, which happens to be a folder in my Apache directory. Of course your path will be different for this step; the key is to make sure you get the correct one!
Please be sure to restart Apache after this change—there is no need to restart you computer at any point during this process.
Now we just need to open a new browser window (an existing session will not work, a browser restart is required), and when I type in www.formboss.net:
My local machine is handling the request!
This whole process is actually quite slick and quite common, as it makes development much easier as well.
To switch this behavior off, we just remove the entry form the hosts file:
Extra Links
Finally, it’s worth noting that while the instructions above will work on a general level, the various stacks will have slightly different locations for files, as well as configuration file layouts.
Thus, here are a few links for the various stacks:
XAMPP
http://drupal.org/node/161975
http://www.tildemark.com/software/servers/setting-up-virtual-hosts-with-xampp-running-on-windows-xp.html
http://forums.whirlpool.net.au/archive/569991
http://maff.ailoo.net/2008/07/set-up-multiple-virtual-hosts-on-xampp-for-windows/
http://textpattern.net/wiki/index.php?title=Using_XAMPP_%28Apache-MySQL-PHP-Perl%29_for_Windows
http://www.google.com/search?q=Xampp+virtual+host&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
Zend Server CE
http://blog.servergrove.com/2009/06/10/running-zend-server-on-mac-os-x/
http://forums.zend.com/viewtopic.php?f=8&t=239
MAMP
http://www.aschroder.com/2009/02/how-to-set-up-apache-virtual-hosting-on-mamp-for-magento/
http://forum.mamp.info/viewtopic.php?t=122