Note: This post is from 2005, I’m not sure what, if anything, is still relevant.
Drupal is an opensource content management system that runs on PHP+MySQL with a flair for community created content, and a robust developer community that offers a lot of capabilities “out of the box,” and even more by adding community-developed modules. I think I first encoutered it a year or two ago, but really started investigating it a few months ago to support a few projects for my employer and since then I’ve been giving it strong consideration for some personal projects as well.
For the past day and a half I’ve been trying to figure out a good way to use Drupal to manage a collection of sites while minimizing administrative overhead.
The worst case is to install a copy of drupal for each site, along with a separate MySQL database for each site. This isn’t difficult, it probably only takes 10 minutes or so per site, but it hurts my brain to think of doing 10 or 15 sites that way because it means maintaining a separate set of users for each and it means that content can’t easily be shared between sites.
Slightly better is to take advantage of Drupal’s ability to have multiple installations use a single database while sharing certain tables between installations, specifically the table of users. This approach reduces some of the administrative overhead, but still has potential problems for sharing content and the like.
Of course, one can go even further with this approach, and share content tables. Unfortunately, it gives me a headache thinking about what would be shared and what would need to be unique to each installation. It also requires tweaking of the install scripts for each new installation. Getting it repeatably correct probably requires creating custom config scripts, and frankly, I don’t have the skills to write them before my lazyness takes hold.
Of course, sharing content tables doesn’t necessarily solve the whole problem anyway, because, by my estimation, once you share enough of the database between multiple installations, you loose the ability to make the sites appear notably different, at least in terms of the content they display.
What I really wanted was an easy way to have a single drupal installation, and then show a different home page to the user depending on the domain name they used to access it. I figured I could use Drupal’s powerful taxonomy features to identify which domains/sites a given piece of content should appear on, but I wasn’t sure how to make it appear properly on the front page of the individual sites. There are suggestions for redirecting a subdomain to a particular page using Apache mod_rewrite, but if I read things right, this results in the loss of the original host name.
I went digging through the drupal site for options. I found a number of people looking to do similar things, and I noticed that future versions of Drupal may have Publish-Subscribe functionality that will be useful for this sort of application, but I didn’t find a real solution for right now that wasn’t going to require more custom coding that I was comfortable with doing myself.
Then I hit upon the solution. Drupal lets you host multiple sites off a single copy of the code by setting up separate settings files for each installation (2nd half of step #4). Drupal lets you configure the default homepage for each site. Usually this is stored in the database, but it can be overridden in the settings file. The solution is to put the two togeather. Make a copy of the main settings file for each site and override the home page to point to a taxonomy view filtered by the category used to flag the content. Now try it out. It seems to work.
So, step by step:
# Install Drupal
# Create a vocabulary that designates where content should appear and enable it for all the content types you want to share between sites (look under “adminster:categories”). If you want content to appear on multiple sites, be sure to check the “multiple select” box.
# Add terms to the vocabulary for each target site.
# Set up DNS aliases for each additional site that points to the main site (I suggest a CNAME record).
# If necessary, configure apache to fulfill requests for the subdomains from the same document root as the main site. If you are using CPanel or another hosting control panel, you might have to “park” the additional domains.
# create copies of the main site’s settings.php (sites/default/settings.php) and place them in “example.com” and the additional site was “zinc.example.com” then you’d need to put a copy of the settings file in “sites/zinc.example.com/”. See the Drupal install instructions for detailed information on naming the directories properly.
# edit the settings.php file for each additional domain:
## Update @$base_url@ to match the name of the additional domain (@$base_url=’http://zinc.example.com’;@ for example).
## Override the front page: @$conf = array ( ‘site_frontpage’ => ‘section/zinc’,);@
# Save the file and try visiting the additional site.
_Note:_ I have installed the pathauto module which provides nice human readable URLs for pages, including taxonomy views. As a result, I can use “section/zinc” to designate the front page, rather than “taxonomy/x/y”. You could also do this by hand configuring things in the path module.
This approach isn’t perfect, but at least this gets me up and running and gives me something to build upon. I hope other people will find it useful as well.
I’d intended to cut bait on this at noon today, and didn’t figure out this little trick until after 5pm, but it’s satisfying to have figured it out.