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 {
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
1 reply
  1. Gongo Banz
    Gongo Banz says:

    I think this is a bad idea - the code is not maintainable, with every update of wordpress you will have to check, if the code still works. Also it is not very clear, if this will work with multiple plugins and themes, all in all you are begging for problems with this "solution" - it would be better to stay inside wordpress world and use wordpress API for changes like this or use a plugin.


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *