Saturday, December 26, 2009

Ubuntu Drupal and multiple Virtual Hosts

A few months back I completed a small project to enable a simple single sign-on approach to product level information access. This wasn't a replacement for OpenID or anything like that, for that would be a crazy thing to take on. What I did was to build a way to assess whether a user had subscribed to one or more information resources within a site that contains many resources. What I created leveraged cookies, an expiry system, and the restful API. This was all good.

To develop all this I used an old Dell Inspiron laptop running a UAMP (Ubuntu, Apache, MySQL, PhP) stack. The project is now running in DEV and is moving into QA so I still need my development environment. I've got another development project where I want to evaluate the quiz / question modules available within Drupal and I want to create another virtual host on the UAMP development server. This is what I did to set up another virtual host in addition to the localhost already being utilized by the restful API project;

1) added a drupal to the hosts file with the IP 127.0.0.2

127.0.0.1 localhost
127.0.0.2 drupal

2) added a new file to the /etc/apache2/available-sites folder
3) edited the new file to include the correct virtual host entry pointing toward the drupal directory

<VirtualHost 127.0.0.2>
DocumentRoot /var/www/drupal/
</VirtualHost>

4) enable the site using the a2ensite command with the new file as the parameter
5) restart apache

All good. Now in the local browser I can run an instance of drupal being hosted at http://drupal