Test Several Websites on Your Computer at Once

After watching several videos from last week’s DrupalCon I had an itch to try out Drupal 7 for myself. The problem was I already had a site I was testing on my laptop. I could’ve downloaded it to my test server, but I’ve been testing alot lately at coffee shops with spotty wifi, so I decided I’d add some entries to my hosts file instead and write up a quick How-to. (pre-requisites: You must have apache, php and mysql already running on your workstation. On ubuntu this is as simple as opening synaptic and searching for each of these packages and installing them: apache2, php5, mysql.)

Multiple development websites in 3 steps.

1. Edit your hosts file. On Linux this is located at /etc/hosts. On Windows machines (XP, Vista, Windows 7) it is located at %SystemRoot%\system32\drivers\etc\hosts. On Mac OS X, its located in: /private/etc/hosts add a new entry for each website you want to test (don’t worry you can add more later): d7 d6 in this case I added two entries: one to test drupal 6, and a second to test drupal 7. To check that everything is working, open up a teriminal and ping d7 you should see something like this:
$ ping d7
PING d7 ( 56(84) bytes of data.
64 bytes from localhost ( icmp_seq=1 ttl=64 time=0.044 ms
64 bytes from localhost ( icmp_seq=2 ttl=64 time=0.047 ms
64 bytes from localhost ( icmp_seq=3 ttl=64 time=0.051 ms
64 bytes from localhost ( icmp_seq=4 ttl=64 time=0.055 ms
2. Edit your Apache config file Add a
<VirtualHost *:80&gt;
    ServerName d7
    DocumentRoot /home/bart/Public/drupal-7.x-dev
<VirtualHost *:80&gt;
    ServerName d6
    DocumentRoot /home/bart/Public/drupal-6.16
3. restart apache
$sudo apache2ctl restart
Now you’re ready to test the websites by opening up the URLs: http://d7 and http://d6 in a browser. As a bonus: go check out the DrupalCon2010 screencasts at archive.org.