mertner.com/allan

Choosing and configuring the engine for mertner.com

Tags: — Allan @ 6:31 pm

When Morten and I decided to “do something” about our web site several months ago, we went through lots of thoughts. A full-blown CMS system is quite heavy and probably requires more customization than we want, but the blogging engines were mostly a bit too primitive.

Admittedly, our requirements were probably not standard ones. We wanted to
* have a nice home page for each member of the family
* have somewhere to show site news and updates
* have a place to put static stuff like a CV, contact details, etc
* use a system that doesn’t rely on frames or tables but uses CSS for layout
* make sure it was easy to use. We probably won’t blog very often.
* use something customizable so we could change the look and feel and also make use of plug-ins, perhaps write a few ourselves.
* use something Free (i.e. paying for it was OK, but not proprietary)
* have multiple blogs so each person can have his or hew own blog


After a lot of research, which included looking extensively at [this site](http://www.asymptomatic.net/blogbreakdown.htm), we decided that [WordPress](http://www.wordpress.org) might fit the bill. The only problem is that it only supports a single blog per installation, and we didn’t want to install several copies of the software since we would invariably forget copying a few files now and again.

Since the site runs on Linux, we decided to go for it anyway and try to set up virtual directories for each user, all pointing to the same installation. This way, any change to any of the files would immediately be reflected for all sites.

With this approach, the first hurdle to overcome is to ensure that each virtual WordPress instance uses its own database. At this point, I decided I might have to learn a bit about PHP. Fortunately it’s quite easy, so the story doesn’t end here 🙂

The default installation uses a file named wp-config.php to store this information – a hack to choose a different setup based on the URL prefix was required. I copied wp-config.php to config-default.php and replaced wp-config.php with code to do just that. Download it [here](http://www.mertner.com/sitecode/wp-config.phps).

The interesting lines in this file are reproduced here:

require( dirname(__FILE__) . '/wp-includes/my-functions.php' );
$configfile = '/config-default.php';

$user = get_virtual_user();
if ($user != "/") {
  $configfile = '/config-' . $user . '.php';
}

The get\_virtual\_user function is defined in [my-functions.php](http://www.mertner.com/sitecode/my-functions.phps) and performs URL matching to return the name of the current user. This is then used to choose the right config file – and each config file contains similar settings but a different database table prefix. This way, all sites use one database but do not share tables between them.

[my-functions.php](http://www.mertner.com/sitecode/my-functions.phps) also includes a new function that I call in index.php. The print\_virtualuser\_list function emits links for each of the virtual users to allow a nice menu for switching between user blogs to be displayed at the top of the page. This is a snippet that I put before The Loop in index.php:

<ul id="navlist">
 <?php print_virtualuser_list(); ?>
</ul>

A few other edits in index.php were required to make the site contents just right: I don’t want a calendar so it was axed, and IE is truly horrible at almost everything so I use [FireFox](http://getfirefox.com) instead and added a link to get it in the meta section when an IE user browses the site.

For more info, have a look at these related posts:
* How to add another user to the multi-user blog
* How to make Fake Folders work with a multi-blog setup
* A plugin-related caveat to consider