Forum Moderators: open

Message Too Old, No Replies

Multiple Wordpress site, one codebase, without WPMU

         

ergophobe

5:09 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Disclaimer: this is probably a bad idea. But I've mentioned it a few times and have gotten a couple of questions about it, so...

How to run multiple Wordpress sites from one codebase without WordpressMU

Why? So that you can upgrade one codebase for all sites and make upgrades easier.

I've mentioned before that I've experimented with running multiple sites on one Wordpress codebase without WordpressMU. This seems to work pretty well, but know that WordpressMU is specifically designed to do this and probably works much better in most cases. I promised myself I would have another look at WordpressMU before I posted this so I could do a more meaningful comparison, but I'm just not finding the time.

There are some differences though. WordpressMU keeps everything in one database. With this method, each blog has its own database. On the plus side that means that you can backup each blog separately. I like to have a cron job that does an SQL dump, gzips it and sends it somewhere (typically a gmail account associated with the site, as in example@gmail.com for the site example.com). For sites that change regularly, I do it regularly. For others, I might run the cron job once or twice a month. So I like having one DB per site.

On the other hand, if you're actually maintaining a large number of sites, there's still an upgrade hassle in some cases. Minor upgrades are no issue, but when the upgrade requires a database change, you have to run the database upgrade script independently for each and every site. If you forget, your site could have issues or be brought down entirely. So that's a serious downside.

So, you should probably run WordpressMU unless you absolutely can't. If there is in fact some reason that WPMU just doesn't work for you, here's an alternative.

1. Set up each site so that the DNS resolves to a directory on your server

example1
example2
example3

2. create the required database for each site.

3. Make it so these directories are actually symlinks to the directory that holds the one copy of Wordpress to rule all sites.

4. For file uploads, create directories for each one of the sites as well so that those stay separate.

3. Set up your wp-config.php so that it tests for the incoming URL and chooses the database and uploads directory appropriately. The code would look like this.

--------------


// allowing for multiple blogs using symlinks
// we grab the server name, lop off the www if present so it works
// with or without.

$server_array = explode(".", $_SERVER['SERVER_NAME']);
if ($server_array[0] == 'www') {
array_shift($server_array);
}

$server = implode('.', $server_array);

// now we check a specific whitelist of servers
// for each server, we set the same set of parameters just like
// we always do in WP, but now on a per-domain basis. The same thing
// could be achieved with subdomains and even subdirs by grabbing other params.
//
// UPLOADS is not typically set in the WP config.
// It is used in wp-includes/functions.php.
// UPLOADS overrides the database parameter upload_path which is set on the
// Miscellaneous Options page.
// The option set on that page and stored in the DB is now worthless.

switch ($server) {
case 'example1.com':
define('DB_NAME', 'example1'); // The name of the database
define('DB_USER', 'e1user'); // Your MySQL username
define('DB_PASSWORD', '132bsDFfh'); // ...and password
define('UPLOADS', 'wp-content/uploads/e1/');
break;
case 'example2.com':
define('DB_NAME', 'example2'); // The name of the database
define('DB_USER', 'e2user'); // Your MySQL username
define('DB_PASSWORD', '4v9eNd'); // ...and password
define('UPLOADS', 'wp-content/uploads/e2/');
break;
case 'example3.com':
define('DB_NAME', 'example3'); // The name of the database
define('DB_USER', 'e3user'); // Your MySQL username
define('DB_PASSWORD', 'art4v9eNd'); // ...and password
define('UPLOADS', 'wp-content/uploads/e3/');
break;
default:
echo "Whoops!";
}


So again, I'm not saying this is a good idea, but just another tool to have if you can't or don't want to use WordpressMU