Tips & Tricks
- May 26, 2010
Wordpress single install / multiple blogs
Yes it is possible to host multiple sites for multiple customers with Wordpress. The Multi User feature we expeted in wordpress 3.0 will satisfy bloggers only but we need something more specific. The technique I describe here is similar to the one described here in the sense that it directs the database configuration constants to specific databases instead of table prefixes as seen a lot. The advantage obviously is that you keep a single install of wordpress and only have one codebase to manage , while databases remain independant.
- create wp-domains folder, and inside one folder for each domain, example wp-domains/mysite.com
- add the following code to wp-config.php : this coding allows a defualt domain to remain active even when the configuration file does not exist, at the expense of a loss in performance. But It is useful to show what’s missing.
$domain = strtolower( str_replace( “www.”, “”, $_SERVER["SERVER_NAME"] ) );
$domain = preg_replace(’[^a-z0-9\.-]‘, ”, $domain );
$domainDirectory=”/wp-domains/” .$domain;
$domainConfig= dirname(__FILE__) . $domainDirectory . “/db-config.php”;
if ( file_exists( $domainConfig ) ) {require_once( $domainConfig );} else {
$dbuser=”defaultdomaindatabase”;
$dbpwd=”password”;
if ($domain!=”defaultdomain.com”)Â echo “missing ” .$domainConfig;}
- replace definitions with variables in wp-config.php
define(’DB_NAME’, $dbuser);
define(’DB_USER’, $dbuser);
define(’DB_PASSWORD’, $dbpwd);
Once this is working with your default  domain, setup virtual hosts  in Apache and try a new domain. Remember on a new install to setup the upload folder in wordpress admin settings.
Multi site config for Wordpress : Compatible plugins
I’m running the following plugins and they work perfectly
- WP Super Cache : works fine because the cache filename coding alogrithm includes the domain name


