As you can probably tell from this blog, WordPress is my favourite blogging tool. I've been using it for a couple of years now, and during that time I've been really impressed by it. So when I was recently asked if a single copy of WordPress could be used to power several blogs, I was optimistic that it would be up to the job.
And it didn't disappoint me...
There are a number of ways you can host multiple blogs with WordPress:
- WordPress MU (multi-user) - This is system that powers all blogs at wordpress.com, Le Monde, Harvard Univeristy etc...
- Batch management of blogs with WP-Create and WP-Upgrade - These scripts let you install multiple blogs in parallel, however each one would get it's own installation.
- Modifying wp-config.php to choose a different database per hostname. This uses the standard wordpress scripts.
Since I wanted to use a standard wordpress installation, and I didn't want to install it multiple times, I chose the 3rd option. Wordpress stores most of it's configuration in it's database, so all you need to do is modify wp-config.php to point at a different database depending on the hostname of the site being accessed:
// Ignore the www. part of a hostname
$host = eregi_replace('^www\.', '', $_SERVER['HTTP_HOST']);
switch ($host) {
case 'site1.co.uk';
$db = 'site1';
break;
case 'site2.co.uk';
$db = 'site2';
break;
default:
header("HTTP/1.0 404 Not Found");
exit();
break;
}
// ** MySQL settings ** //
define('DB_NAME', $db); // The name of the database
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'hostname');
Simply add the existing database settings code with the code above, and then create a new empty database for each blog you want to host. You will need to run the install scripts for each blog, e.g. http://www.site1.co.uk/blog/wp-admin/install.php
References:
- Enterprise 2.0 anyone? - How to: multiple blogs, one Wordpress installation
- WordPress Codex - Installing Multiple Blogs