Virtual Multiblog

for WordPress

a.k.a. "Strider's Modified Mertner Method Multiblog"

Home Page: http://striderweb.com/nerdaphernalia/features/virtual-multiblog/
Readme Updated 17 July 2008

Run more than one blog off a single install of Wordpress. Each blog is managed as a complete separate install -- separate admin sections, separate users, etc. They will happily co-exist with different themes and plugins activated. The biggest advantage is that you will only have to keep one set of program files up-to-date, and this method should be expandable to as many different blogs as you like.

DISCLAIMER

USE AT YOUR OWN RISK. If it blows up, or deletes your hard drive, or in any other way does something you don't want it to do, too bad. Not my responsibility. If you don't agree with those terms, Don't Use It.

THAT BEING SAID... I (Stephen) use it myself. I believe it works well, and if you do have problems, I would be interested in knowing about them so I can make improvements to the system.

CONTENTS

Installation

First I'll give a basic overview of how this works. Wordpress will be installed normally in one directory, and additional blogs will be created by pointing other domains, subdomains, or "directories" at that one install. "Directories" in this case are actually Symbolic Links (or "symlinks"), which are a type of secondary representation of a directory -- somewhat similar to a Mac alias or a Windows shortcut. There is a single change to the WordPress code to make this all work: a modified configuration file that loads a different configuration depending on what directory or domain it thinks it's in. Everything else is stock standard WordPress, which makes this method extremely compatible with existing plugins, themes, and add-ons of all kinds.

Easy Setup

CRITERIA -- You can use easy setup if all blogs' data will be held in a single database.

For these directions, we'll use an example setup. We are going to set up four blogs, at http://www.catblog.com/, http://www.dogblog.com/, http://mutts.dogblog.com/, and http://www.catblog.com/persians/

NOTE: As of version 2.4 the plugin is no longer needed.

  1. Install the WordPress files as usual.
  2. Place the "multiblog" folder in the wp-content/ directory.
  3. Move the wp-config.php file up to the directory in which you installed WordPress.
  4. In the wp-content/multiblog/config/ folder, rename mb-autoconfig-sample.php to mb-autoconfig.php. Open mb-autoconfig.php in a text editor. Input your database login information.
  5. Set up whatever symbolic links, subdomains, or domains you wish so they all point to the directory with WordPress installed. Note: redirects and "parking" will not work for domains -- the domains must be set up directly on the server. (In Apache that probably means "Virtual Hosts".)
  6. In this example:
  7. With your web browser, go to each blog and set things up as normal through WordPress.

You're done! Told you it was easy!

Advanced Setup

Advanced setup allows for a bit more security, and allows for a default "fallback" blog. In the future, advanced setup will hopefully allow for advanced template functions such as calling a list of links to all blogs in the multiblog setup.

For this example, we're going to create http://www.catblog.com/, http://www.dogblog.com/, http://mutts.dogblog.com/, http://www.dogblog.com/fido/, and http://www.catblog.com/celebrities/morris/

  1. Follow Steps 1-6 from the Easy Install.
  2. In wp-content/multiblog/config/, rename mb-users-sample.php to mb-users.php. Open mb-users.php in a text editor. Populate $vusers[] according to the instructions there. For this example we have:
    $vusers[] = 'catblog.com';
    $vusers[] = 'dogblog.com';
    $vusers[] = 'mutts.dogblog.com';
    $vusers[] = 'catblog.com/celebrities/morris';
    $vusers[] = 'dogblog.com/fido';
    
    Do not use Trailing Slashes. Save and close the file
  3. For this example:
  4. With your web browser, go to each blog and set things up as normal through WordPress.

OPTIONAL: Giving a blog its own config file

Any blog using this setup can have its own completely separate config file. You can do this if, for example, you want to store a blog's data in a separate database. You can do this for just one blog, all of them, or none of them.

Go into the wp-content/multiblog/config/ directory and make a copy of mb-config-sample.php. Rename it to mb-config-VUSER.php (See below for how to determine the VUSER.) Open that file in a text editor and set the database information and, optionally, the $table_prefix. If you use the same database for multiple blogs, you must set a different $table_prefix for each. If you don't set $table_prefix, it will be auto-configured.

Determining VUSER

If you use the "Easy Setup" method, then your VUSER is the domain or subdomain, plus directory if any, except that all non-alphanumeric characters are replaced with an understroke ('_'), and any 'www.' is removed. (Non-alphanumeric = anything not a letter or a number.)

If you set up the $vusers[] array in mb-users.php, then the current VUSER for a blog is whatever that value is, cleaned up as described in the previous paragraph.

For example: With "mutts.dogblog.com", the VUSER is "mutts_dogblog_com". For "www.catblog.com/morris", the VUSER is "catblog_com_morris" and the config file is mb-config-catblog_com_morris.php. (Note the difference between dashes and understrokes!)

OPTIONAL: Custom Configuration Location

You can change the location of your config folder. Open up the wp-config.php file in a text editor and change the $vmb_configpath variable. This has a couple advantages:

OPTIONAL: Easy Subdomains (Advanced Setup only)

Let's say you have a whole bunch of blogs you want to put on subdomains of dogblog.com. You can save yourself some typing by setting $mydomain = 'dogblog.com'; in the mb-users.php file. If that is set, you can add subdomain blogs by name alone, e.g. $vusers[] = 'mutts'; would work for both http://mutts.dogblog.com/ and http://www.dogblog.com/mutts/. Mind you, both of those would be the same blog with the same WordPress tables (and note the caution in Step 3 of Advanced Setup). You can't set two different domains to $mydomain.

Sorry -- this section isn't complete yet. The simplest solution for the non-techie is to ask your hosting provider to do it for you. :)

Slightly longer answer -- there is no simple set of instructions, as setting up Symbolic Links can be different depending on your Operating System, disk filesystem, PHP version or configuration, server configuration, and so forth. Nonetheless, I will try to get some pointers up at some point.

Let me put it another way. I don't make my own symlinks -- I call my web host, Mike. However, on my test site (running on my OS X laptop via MAMP) I have a utility called Cocktail that makes them for me.

If you are on a Unix-like system (including Linux or OS X) you can probably open a Terminal window and use the ln command.

New Functions

The following are stable and can be called in templates or plugins:

constant VUSER
The current virtual user. This is handy for creating Themes, for example, as you can call different template files for each VUSER.
function $vmb->get_bloginfo( $show )
The following are recognized for $show:
function $vmb->get_sysinfo( $show )
The following are recognized for $show:

If you are just using domain or subdomain-based addressing, the default WordPress rewrites will work just fine. If you are using directory-based blogs, and you want to use "pretty" permalinks, you will need to make some changes to your .htaccess file:

Open up your .htaccess in a text editor. Delete everything between "# BEGIN WordPress" and "# END WordPress". Above the "# BEGIN WordPress", insert the following (putting in your blog names of course)...

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} (/cat|/dog)?/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . %1/index.php [L]
</IfModule>

... and then set permissions on the .htaccess file so that WordPress can not overwrite this. For additional blogs, simply add the symbolic links inside the parentheses on the third line like so: (/cat|/dog|/bird|/lizard)?/

Contribute

Was this download worth a dollar to you?

I've put a lot of time and effort into making this work well. I use it myself, and I'm gratified that so many others have found it useful. If you would like to support my efforts, please consider making a donation:

History/ Acknowledgements


v2.5
* WordPress 2.6 compatible -- can handle moving wp-content directory
* New VMB_DIR constant
* New VMB_URL constant
* Fixed readme to reflect lack of plugin
* Marked get_virtual_user with _deprecated_function()
* Added WP_SITEURL and WP_HOME to diagnostics
* Stripped wp-config.php -- functions moved to multiblog/resources/
* Added "Ohz' Admin Drop Down Menu" icon 


v2.4 (9 July 2008)
* Fixed two recent bugs in get_virtual_user() that could prevent VUSER from being determined correctly (Thanks, David Mohr)
* Eliminated plugin.  That functionality now works automatically

v2.3 (12 June 2008)
* Updated admin for WP 2.5:
	- added direct link from plugins page
	- added footer
* Code cleanup and abstraction -- e.g. most functions called via "$this->"
* Added $vmb->get_plugin_data()

v2.2.3 (22 April 2008)
* BUGFIX: If another plugin called wp-config.php directly, VUSERS came up wrong 
    (thank you "Pozmu" for the catch and the fix.)
* Fixed typos (duh) in sample configuration files
* Added SECRET_KEY define to sample configuration files, per changes to 
    the standard wp-config.php in WordPress 2.5

v2.2.2 (7 April 2008)
* BUGFIX: Security hole introduced in 2.2.  VUSER detection should key 
    off of $_SERVER['SERVER_NAME'] instead of $_SERVER['HTTP_HOST'];

v2.2.1 (31 March 2008)
* All default config files now end with "-sample.php" so that upgrades 
    don't overwrite existing configurations.

v2.2 (29 March 2008) 
* Most information calls abstracted through get_*info functions
* Class declared as global $vmb.  Internal calls abstracted through $this->
* BUGFIX: get_virtual_user() -- line to get dirname( $rootpath ) was missing

v2.1.2 (never released):
* Moved most functions into vmb class
* Added MySQL and PHP versions to vmb::diagnostics output
* Other minor changes to vmb::diagnostics

v2.1.1 (16 December 2007):
* SECURITY FIX: Multiblog Options panel was accessible to all user 
    levels.  Now requires 'manage_options' capability

v2.1 (15 Dec 2007):
* Blogs can be in subdirectories, e.g. 
	http://example.com/blogs/cat/ and http://example.com/blogs/dog/
* Changed all mb_ naming to vmb_ (functions and variables) to avoid 
	confusion with PHP multi-byte functions
* vmb_diagnostics allows override
* New function: vmb_get_homepage()
* New function: vmb_get_bloginfo()
* code abstraction and cleanup
* new support plugin
* Tightened replace in vmb_clean_vuser() for better security
* If somebody calls vmb_get_virtual_user(), it just returns VUSER 
	instead of re-calculating (unless an $altroot is passed)
* Re-added get_virtual_user() function for backwards compatibility 
	with original Mertner version

v 2.0 (21 Nov 2007): Hugely improved ease of setup and improved 
	(i.e. fixed) usability with domains and subdomains.  Ability to 
	auto-configure all, some, or none of the blogs, adding great 
	flexibility between standardized or custom configurations on a 
	blog-to-blog basis.  Also added user-accessible -- and stable -- 
	functions, and the VUSER constant.

v 1.1:
*	New Owner: Stephen Rider
*	Extensive reorganization, code cleanup, and full documentation.
	Among other improvements, the whole package became self-contained 
	within the wp-content directory.

v 1.0: The basic symlink methodology was created by Allan Mertner.


PLUGIN:

Plugin retired as of VMB 2.4 (9 July 2008)

v2.3 (2 June 2008)
* Fully abstracted plugin file -- all functions moved to virtual-multiblog.php (renamed from vmb-functions.php).  In theory plugin file should never need an update again.

v2.2  (29 March 2008)
* Moved pretty much everything over to mb-functions.php for easier maintenance.  One or two more tweaks and we may never have to upgrade the plugin file again!

v2.1.2 (never released)
* Put plugin functions in vmbp class
* Added get_plugin_data function

v2.1.1 (16 December 2007)
* Bugfix -- Security hole -- Multiblog options tab was accessible to anybody seeing the admin pages.

v2.1 (15 Dec 2007)
* Added basic Options page -- currently shows diagnostic info and homepage link
* Changed all mb_ to vmb_ per system changes

v2.0.1
* Added VUSER check to mb_bloginfo_filter() -- don't take credit if system is not being used!

Many of the improvements to version 2 were based upon or inspired by commenters to my blog. To them, and to everyone who has sent comments, I am grateful.

Good luck. Have fun.

Stephen Rider
http://striderweb.com/