Hosting Multiple Blogs With a Single WordPress Installation

This post is going to be the first in a short series outlining how anyone can take measures to simplify WordPress installations on shared or private hosting solutions, improving security and reducing maintenance time.

Getting Many from OneIt's a common problem: We have dozens of WordPress installations on our web server(s), and updating each and every site when a plugin is updated or a new release of WordPress becomes available is a huge time sink.  WordPress MU looks nice but installation is pretty complicated for most people and it's outright forbidden on most shared hosting accounts.  So what can we do to simplify software management?

Why not run each WordPress site from the very same source?

Madness, you say?  I disagree.  As of this post, I am running 9 web sites with a single installation of WordPress, and there will be another 8 added (a.k.a. rebuilt from backups) over the next week.

Here's how you do it.

Multi-Site, Multi-Domain, or Both?

The first thing we need to identify is whether you'll be hosting multiple sites (,, etc.) , multiple domains (,, etc.), or both configurations.  The reason this is important is because it will play a role in how we set up WordPress' config.php file and where the installation files are put.  For the sake of this example, I'll show you how to handle both multi-site and multi-domain.

First, you'll need to install WordPress to some public-facing directory on your server.  For example,  From there, install WordPress normally.  We'll be making the super-easy changes in a few minutes.

Note: If your main site ( will be using the very same installation of WordPress, be sure to copy the index.php file in /wp/ to your website, making sure that you're pointing to the WordPress installation folder.  Here's an example:

/** Loads the WordPress Environment and Template */

Be sure not delete index.php from the /wp/ folder. The original file will be used for every other site.

We're almost done the hard stuff!  Now it's time for the sweet stuff.  But, before getting too far ahead of ourselves, we need to answer a question:

Single Database or Multi-Database?

The nice little trick I'm about to show you will allow you to put every blog into a single database, or into multiple databases.  It's really up to you how you proceed.  For the sake of this example, I'm going to show you how to handle multiple databases, including shared databases.

Add the following code just before the line that reads define ('DB_NAME', 'YourDatabaseName'); :

$host = $_SERVER['HTTP_HOST'];
$parts = explode('.',$host);
if ($parts[3] = "") {
$domain = "www." . $parts[0];
} else {
$domain = $parts1;
}switch ($domain) {
case "www.YourDomain":
$pre = "wp0_";
$db = "DatabaseOne";
case "sub1.YourDomain":
$pre = "wp1_";
$db = "SharedDatabase";
case "sub2.YourDomain":
$pre = "wp2_";
$db = "SharedDatabase";
case "www.DomainTwo":
$pre = "wp_";
$db = "DatabaseTwo";
case "sub1.DomainTwo":
$pre = "sub1_";
$db = "DatabaseTwo";

From here, we need to  put the variable names into the declaration lines like so:

define('DB_NAME', $db);
$table_prefix = $pre;

We're almost done!  But, before going further, you have probably noticed that each one of these three databases would need to have the same username and password.  If you want to have different User/Pass credentials for different databases, you can add more variables to the case statement.

Now the magic …

Adding Domains and Sub-Domains

When adding a WordPress-powered domain or sub-domain, simply point the home address to your WordPress installation folder.  For example: -> / -> /wp/ -> /wp/ -> /wp/ -> /wp/

You're probably noticing that each of these domains will be using the very same wp-content/uploads directory for media.  If this is a problem, it can be changed in WordPress to something more your liking.  In my case, I created yet another sub-domain called "uploads" and pointed it to /wp/uploads/.  From there, each domain has their own subdirectory.  The advantage here is that all uploads are in their own little corner of the server and can be easily backed up or restored in the future.

Done and Done?

Weighing Pros and ConsSo, that's all there is to it.  This is not incredibly difficult to implement and comes with advantages such as being able to update every blog's core files and plugins simultaneously.  That said, there are some plugins that will not work well under this configuration.

If your sites experience high traffic volumes and you want to use WP Super Cache, it will only work on one site.  This is because the cache directory is set in wp-content/cache.  Unfortunately, this means that if two pages were to use WP Super Cache, they would write and access conflicting files.  I have also noticed some /tmp accessing problems while using an older version of FireStats, but I'll be testing the more current releases to see if they're more friendly to this configuration.

Of course, the biggst disadvantage to this setup would come if you are sharing sites with friends or family.  The newer versions of WordPress allow people to install plugins directly from the admin panel, and this can be a problem if one of these plugins contains a hidden exploit.  Rather than damange just one blog, it could damage many.  However, with proper education, you can make sure that other people do not cause trouble for everyone else.

So there you have it.  A quick and simple way to share one WordPress installation across multiple sites.  In the next installment of this series, I'll show you how to take multiple WordPress databases and merge them into one big database without doing several Import/Export functions through the WordPress admin screens.

  1. "." . $parts[1