Virtual Multiblog for WordPress

<?php echo "Hello Again, World!"; ?>

Note: If upgrading to VMB 2.5 from a previous version, please read the upgrade instructions.

Greetings and salutations.

This is my second blog, which is here to serve as a repository for the really die-hard geekery that I feel just doesn’t belong in my regular blog. When I realized the need for a second blog, installing it ended up being a longer process than i anticipated, and I thought I would share the fruits of my experience.

Let me step back for a moment. I am a true hacker at heart, in the traditional sense: I love to pull things apart and take a look. To see how they work and how they might work better. I’m also an avid Mac-head, and since the rise of OS X, I’ve been learning the ins and outs of its Unix-like underbelly.

In a nutshell, my computer is highly customized.

A few years back I got a second computer — a laptop — and quickly discovered that while keeping one computer tweaked to prime operation just the way I like it is kind of fun, trying to keep two computers in such a state, and relatively synchronized, is a frustrating exercise in futility.

I also know a good bit of web coding. As I’ve been working with WordPress for a couple years now, I’ve come across a number of good plugins and expansions along the way. Beyond issues involved with installing them, (which is admittedly pretty easy, usually) over time I have to keep up with updates to these — not to mention updates to Wordpress itself. From time to time I even delve into the plugin files myself and make improvements….

And I want to put in a second blog? Am I nuts??? Thinking of what a pain it would be to maintain two copies of WordPress, I started looking into the various multi-blog solutions people have come up with. Most of them involve a lot of weird modifications to several files and basically comprise major modifications to large swaths of the WordPress code that are fundamentally incompatible with the regular version.

I am a great fan of what I consider “elegant” coding, which means that the designer does his job with the simplest and most straightforward methodology possible. And I found a very elegant solution to the “multiple blog on one install” question. Allan Mertner came up with something that blew me away with its simplicity and power.

WordPress holds all of its data in a MySQL database, and there is a single file called wp-config.php that holds the database login information. Allan looked at this and realized that if you can change that one file, you can completely replace the blog. With this key realization he came up with a cunningly straightforward multi-blog system:

  1. Replace the standard wp-config.php file with a new version that calls a different configuration set depending on what directory it’s in.
  2. Set up symbolic links that serve as “virtual directories” that all point to the WordPress directory.

Using the example of this site, I have an install of WordPress in the root web directory, and a symbolic link called “nerdaphernalia” (that’s right, you’re soaking in it!) that points back to the root. The modified wp-config file points to either the default or nerdaphernalia config file, depending on which of those two directories it thinks it’s in.

So other than a happy user, where do I come in in all this? Well, I made a number of improvements. First, Allan’s system was great, but it required us to install various files in and around the core WordPress files, which for me at least defeats part of the purpose of using a multiblog system in the first place. I’m trying to make updates easier, remember? Updating WordPress generally involves deleting everything but the wp-config.php file and the wp-content folder, and then dropping in the new versions of everything else; but if there are important but non-standard files strewn about, I can’t just do that. I have to remember to go through and preserve those files, and then replace them when they’re done. Add in a few plugins that work the same way, and we have a real hassle.

So first off, I tucked all the files, except for the one modified wp-config.php, into a folder in a safe place. Next, I greatly streamlined the install process. At a minimum, the user only need edit a single configuration file, autoconfig.php. If desired, the various blogs can each have individual config files, but it’s no longer necessary.

I’ve added user-accessible functions (and the really handy VUSER constant) that can be used in themes and plugins. I’ve added the ability to customize the location of the configuration files, so the security-conscious can move them entirely out of the Web directories if they wish. Overall, we are left with a easy but powerful system for running virtually any number of blogs off a single install of WordPress.

Install instructions are included with the download. Still have questions? Check out the readme and the FAQ. (Note: Sometimes the readme will list a higher version than the download. That happens if I have a development version installed.)

User “JZ” is selling written instructions for installing the system. (Please Note: I have not even seen his instructions, I’m just letting you all know.) More info in this comment.

…And if the directions are worth money to you, perhaps the actual software is worth something as well?

Download

Here’s what you’re really looking for: the download link. Have at it!

Virtual Multiblog v2.5

History/ Acknowledgements

For a detailed history, please see the readme file in the download.

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.

383 Comments

Pages: « 111 12 [13] 14 1520 » Show All

  1. #241 | Posted July 17, 2008 at 7:01 pm

    @mark

    [Animation: Orson Welles (as Citizen Kane) clapping his hands]

    First, a question. Do you actually have a folder set up for rcnblog? There should be NO FOLDER for it. When I browse to either http://www.bojac.co.uk/rcnblog/ or rcnblog.bojac.co.uk I get a Index of Directory page. I did the same thing - it took me a while to wrap my head around the fact that I could create a subdomain without creating a folder for it.

    Meanwhile, here is what I did with the config and users files - see if it helps at all to have a direct example:

    In the mb-users.php file:
    $vusers[] = ‘main.notmymothersblog.com’;
    $vusers[] = ‘moms.notmymothersblog.com’;

    // OPTIONAL: If using subdomain (”dog.example.com”) addresses with
    // one domain, set $mydomain to the domain name —
    // e.g. ‘example.com’ — and then you only need set the subdomain
    // (’dog’) in $vusers[];

    // You may only set one $mydomain.

    $mydomain = ”;

    In the mb-config-moms_notmymothersblog_com.php file:

    // Optional. Try setting these if you’re having trouble with redirects
    define(’WP_SITEURL’, ‘http://moms.notmymothersblog.com’);
    define(’WP_HOME’, ‘http://moms.notmymothersblog.com’);

    Finally, to answer “where are the files hiding?”, there is only one set of files, no matter how many virtual blogs you set up. You upload those files to a directory and create a virtual host for each blog that you want to run and point the virtual host at the folder where you uploaded the blog files. There are no other files needed, and no other folders. All the installation does is create and set up the database tables for a new blog. As long as your config file points to the right database (and/or the right table prefix) you should be fine. I suspect having a folder with the name of the directory or folder may confuse the code, and when it can’t decide what it should do, it defaults to the first blog.

    I’ll post a quick troubleshooting checklist in a separate comment.

  2. #242 | Posted July 17, 2008 at 7:20 pm

    Troubleshooting Checklist:

    1. Do you have folders set up for subdomains or directories? If so, remove them.

    2. Are the tables for your new blog created on the right database (or with the right table prefix if you’re using a single table)? If not, check the connection information and table prefix in the individual config files.

    3. Does your mb-config-subdomain_yourdomain_com.php file have the right database connection information if you’re using separate databases?

    4. Does your mb-config-subdomain_yourdomain_com.php file point to the right table prefix for each blog?

    5. CHECK THE TABLE PREFIXES CAREFULLY. Are they the same as the ones in your config file? I had problems with extra underscores.

  3. #243 | Posted July 18, 2008 at 12:32 pm

    Mark –

    Okay, it looks like you’re trying to do the main domain, plus /espana/. I have to say that it’s weird that the exact content is repeating at the two addresses. Normally I would expect espana to be redirecting to the root domain. I suggest you un-set WP_SITEURL and WP_HOME if you have them set. That could be obscuring something else.

    Here’s why: WordPress stores its own base URL in the database, so if a second install accesses a different blog’s tables, it will usually read the URL out of the DB and redirect to the blog that “owns” those tables. Setting those two constants can override that, which could result in the strangeness we’re seeing on your site.

  4. Mark
    #244 | Posted July 19, 2008 at 7:13 am

    Stephen -
    I’v tried to include below, as much info as possible to help locate the source of the problem.
    I have un-set WP_SITEURL and WP_HOME, there is no noticable difference.
    // Optional. Try setting these if you’re having trouble with redirects
    // define(’WP_SITEURL’, ‘http://www.myecovideo.com/espana’);
    // define(’WP_HOME’, ‘http://www.myecovideo.com/espana’);

    All four additional blogs are installed, but I’m focussing on espana, as what works for one should work for all.

    I have my main blog in a directory (named blog) of myecovideo.com. The symlinks (created by my host) are directories within myecovideo.com & point to directory blog. Each symlink replicates the contents of the directory blog including plugins etc.
    See tree image here: http://www.myecovideo.com/File-tree.png

    If I remove myecovideo.com/blog from mb-users.php & remove mb-config-myecovideo_com_blog.php from main blog mb-config file, then both main blog & espana open as new ‘Hello World’ blog pages for australia which is now top of VUSERS list.
    $vusers[] = ‘myecovideo.com/blog’;
    $vusers[] = ‘myecovideo.com/australia’;
    $vusers[] = ‘myecovideo.com/deutschland’;
    $vusers[] = ‘myecovideo.com/espana’;
    $vusers[] = ‘myecovideo.com/norge’;

    I can log into new dashboard of each new blog, which I think shows that DB table prefixes are set correctly. If (as a test) I change the table prefix in the config file, I’m asked to make a new install.
    When I click the ‘visit site’ button, each blog loads the main blog.

    Virtual Multiblog Diagnostics - Main blog
    Version………………. 2.4
    VUSER………………… myecovideo.com/blog
    Config File…………… mb-config-myecovideo_com_blog.php
    WordPress version……… 2.5.1
    ABSPATH………………. /home/coralbne/myecovideo.com/blog/
    PHP version…………… 5.2.6
    MySQL version…………. 5.0.51a-community
    $_SERVER['SERVER_NAME']… http://www.myecovideo.com
    $_SERVER['PHP_SELF']…… /blog/wp-admin/index.php
    $_SERVER['HTTP_HOST']….. http://www.myecovideo.com
    $_SERVER['SCRIPT_NAME']… /blog/wp-admin/index.php
    $_SERVER['DOCUMENT_ROOT']. /home/coralbne/myecovideo.com
    End Diagnostics
    Virtual Multiblog Diagnostics - Symlink blog /espana
    Version………………. 2.4
    VUSER………………… myecovideo.com/espana
    Config File…………… mb-config-myecovideo_com_espana.php
    WordPress version……… 2.5.1
    ABSPATH………………. /home/coralbne/myecovideo.com/blog/
    PHP version…………… 5.2.6
    MySQL version…………. 5.0.51a-community
    $_SERVER['SERVER_NAME']… http://www.myecovideo.com
    $_SERVER['PHP_SELF']…… /espana/wp-admin/index.php
    $_SERVER['HTTP_HOST']….. http://www.myecovideo.com
    $_SERVER['SCRIPT_NAME']… /espana/wp-admin/index.php
    $_SERVER['DOCUMENT_ROOT']. /home/coralbne/myecovideo.com
    End Diagnostics

    Thanks, Mark

  5. #245 | Posted July 21, 2008 at 4:10 am

    The folder multiblog/plugin/ does not exist in the current .zip file offered for download?

  6. #246 | Posted July 21, 2008 at 4:40 am

    Nevermind… ;)

  7. #247 | Posted July 22, 2008 at 11:33 pm

    Hi

    I’m using WP 2.6 on my self administered WAMP server. Using folders (ie not sub-domains) for each blog.

    Everything works great until I try to set up the permalinks. They just return 404.

    Blogs are at:

    http://rose2/craigsmaths/
    http://rose2/craigswebs/blog/
    

    Here’s my .htaccess in the wordpress folder. It is read only and set up just as in the readme.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} (/craigsmaths|/craigswebs/blog)?/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . %1/index.php [L]
    
    # BEGIN WordPress
    # END WordPress
    

    Having never used multiblog before perhaps this is a 2.6 thing?

  8. #248 | Posted July 23, 2008 at 12:32 pm

    Craig — That looks as though it should work. As a test:

    1. Remove your custom stuff from .htaccess

    2. Go into WordPress admin for one of the blogs and set up permalinks. Allow WordPress to put what it wants into your .htaccess

    3. Confirm that permalinks are working properly for that blog with default WordPress .htaccess

    [Update: When you've done this, only the one blog will work....]

  9. #249 | Posted July 25, 2008 at 5:55 am

    can I delete mb-users.php?

  10. #250 | Posted July 25, 2008 at 11:01 am

    Nick — Yes you can. VUSERs and table prefixes will be auto-generated; and it will look for config file names based on VUSER, or use autoconfig.

    See the readme if you haven’t already. :)

  11. Matthew Weaver
    #251 | Posted July 27, 2008 at 4:44 pm

    [Rec'd via email --- manually posted by admin due to comments bug]

    I may be missing this in your readme, FAQ, your content on the pages here, and the associated comment Q&As on your website, so I apologize in advance if this is a repetitive question, but how do I set up multiple virtual/aliased domains to use the same set of database tables–same posts, comments, users, etc.?

    primarydomain.com
    seconddomain.com
    thirddomain.com
    fourthdomain.com

    Wherein all share the same install, the same db tables (users, posts, comments), have different logos based on domain name (found a note on one comment about this), and then based on domain/categories (which is plugin/code I will have to write/adapt), display appropriate posts and comments. Thus, based on the domain entered, the user is given the blog with appropriate domain/category content.

    At this point I have multiblog working but unclear how to set or override the wp_ naming for each domain instance because I do not want the users, posts, and comments to be in separate tables.

  12. #252 | Posted July 27, 2008 at 4:56 pm

    Matthew — So basically what you’re describing is you want the same website at different URLs (plus some extra hacks of your own…).

    You should set the different virtual blogs to have the same table prefix. The only problem beyond that is that the database stores the blog’s URL in it, but you want the same blog different places. To overcome that, go into each blog’s config file and define WP_SITEURL and WP_HOME, e.g.:

    
    // Optional.  Try setting these if you're having trouble with redirects
    define('WP_SITEURL', 'http://primarydomain.com');
    define('WP_HOME', 'http://primarydomain.com');
    

    You should be all set.

  13. Mark
    #253 | Posted July 28, 2008 at 3:31 am

    Hi Stephen,
    Can you help me with my post #244 please?
    I’m stuck for what to try next.

    Thanks, Mark

    [site owner responded via private email]

  14. #254 | Posted July 28, 2008 at 6:09 am

    Firstly thanks for all your hard work on this project, it’s exactly what I’ve been looking for. At the moment I’m one step away from having my setup work perfectly. I have 4 blogs installed in subdomains, my users file looks like this:

    $vusers[] = ‘records’;
    $vusers[] = ‘films’;
    $vusers[] = ’syncronisation’;
    $vusers[] = ’streetangels’;

    $mydomain = ‘rootsydev.co.uk’;

    Each subdomain works correctly, however, if I go to http://www.rootsydev.co.uk, I get taken to records.rootsydev.co.uk, I understand that this is because records is the default installation. How can I make a separate page for the root domain? I do not need a blog here, just a single page with links to each sub-site.

    Any advice would be most greatly appreciated!

  15. #255 | Posted July 28, 2008 at 9:30 am

    Huw —

    Add $vusers[] = ‘default’; to the beginning of your vusers list.

    (Actually, because it’s the default it can be anything — “root”, or “www” or “supercalifragilisticexpialadocious”.)

  16. #256 | Posted August 1, 2008 at 1:46 am

    I wonder if this could be ported for bbpress? I could see this being just as useful there, perhaps more-so as there is no multi-site option for bbpress as of yet (like mu is to wordpress). Just an idea.

  17. pixelgecko
    #257 | Posted August 1, 2008 at 9:02 am

    I’m trying to use the VUSER constant to customize the header for each of my blogs

    domain.com/default
    domain.com/blog1
    domain.com/blog2
    domain.com/blog3

    i’m not all that familiar with php, and would like guidance on where and what to insert the appropriate code to achieve this. you mentioned something in a post above about doing this:

    <img src=”logo-.jpg”>

    do you have any idea if this worked? what i’d like to do instead is specify a different to use, based on the vuser:

    blog1 =
    blog2 =

    is this possible? i googled “multiblog vuser header” and wasn’t able to find anything that really helped. if it’s possible (and i’m sure it is), could you give me some guidance as to how to do this?

  18. #258 | Posted August 1, 2008 at 6:06 pm

    AWESOME Plugin! … Nice touch on the anti-spam quiz ;-)

    any thoughts on how to set-up different individual Favicons for each multiblog?

  19. #259 | Posted August 1, 2008 at 6:54 pm

    pixelgecko and dhkeller — You’ve basically asked the same question, and since people ask about this fairly regularly, I’ll be working up a page for it.

    Short answer: VUSER is a read-only variable, so you can use it as part of a filename to link different files for each different blog…. (You may have to clean up slashes and such… stay tuned!)

  20. #260 | Posted August 1, 2008 at 6:56 pm

    Nick — Probably pretty easily, actually.

    I don’t use bbpress though. You wanna be my tester?

Pages: « 111 12 [13] 14 1520 » Show All

Post a Comment

Your email is never published nor shared.

Subscribe without commenting