Thursday, September 13, 2012

2012 September 13 | Hosting | Multi-Blogging in Wordpress

Goal:  Install Wordpress software one time, but allow multiple blogs (multi-blogging in wordpress) to be deployed within a domain.  One set of software, one set of plugins/themes, but separate posts/pages and upload data for each blog is required.

Reason: I have a domain and wanted to have more than one blog.

(Specifically written for my pal, Justin Hunt.)

1. We assume the blogs will be created using the following steps:

  • Make a sub-domain in your Apache settings.

  • Make a database using phpmyadmin or other means.

  • Follow the naming conventions below (or something similar).

2. Add this code to your wp-config.php file in above where the normal stuff is stored.
$host = $_SERVER['HTTP_HOST'];
$parts = explode('.',$host);
$domain = $parts[0];
$db = "wp_" . $domain;
$dbuser = "wp_" . $domain;
define('DB_NAME', $db);
define('DB_USER', $dbuser);
define('DB_PASSWORD', 'blahblahblah111');
/** MySQL hostname */
define('DB_HOST', 'localhost');

The “domain” variable is the subdomain prefix (for example “” breaks into an array called “parts” with the “explode” command.  Therefore, parts[0] is set to “blog”, parts[1] is “example” and so on.

I used a naming convention with my Wordpress databases in mysql so the database name is “wp_blog” or “wp_<subdomain>” and the user is also the same as the database name.  For simplicity the password is always the same no matter which blog I’m using.

3. Once the blog launches, make sure you have made a sub-directory under the wp-content/uploads  directory for each sub-domain.   This helps to keep the uploaded stuff separate.  For example:

Note: Don’t forget to change the Wordpress Settings->Media to reflect where the uploads data gets stored for each blog!

This makes it easy to maintain the blog system software on your site.  Once you install a plug-in, the plug-in is there for any blog you have.  Same for themes.  But uploads are kept separate.