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

3 comments:

Anonymous said...

Peter,

Thank you!! for this.

I had been trying to set up multisites, but only wanted separate instances of drupal running in separate folder (e.g. var/www/mysite1, /var/www/mysite2 etc).

Your solution was so simple, and maintains all the same links as the live site.

Again, thank you.

Cheers,
Steve

Nittalope said...

Hi Peter, I am a bit confused about a thing:

point 1, how to add a drupal to the hosts file... don't know how to do this, I am a bit new...
The other points are quite easy, can you please explain?

Thank you in advance!

mike

Unknown said...

I am always in search of such articles which provides lots of information on the subject matter for more knowledge. For more knowledge visit

Lamp Development