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.6.2

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.

684 Comments

Pages: [1] 2 3 4 5 6 7 8 9 10 1135 » Show All

  1. #1 | Posted November 23, 2007 at 1:08 am

    I have WP on a test server running Debian. I read your instructions on the multiblog. Created the symlink. However I get a 403 forbidden everytime. I have wp installed in the root directory. However I am not sure how to fix this issue. I have pointed the symlink to various places according to the comments of other users and directions. With no change. It is currently pointed at the root directory(where the wordpress files are located).

  2. #2 | Posted November 23, 2007 at 10:08 pm

    The symlnk should be pointed to the directory in which you installed WordPress.

    Do you only get the error when you go to the symlink, or do you get it on the “real” WordPress directory as well?

  3. #3 | Posted November 23, 2007 at 11:57 pm

    I was only getting errors when I went to the symlink. I did however fix the problem. It was something silly. The mb-config files had .php twice on the file names and apache freaked out about it. I guess next time I will work on stuff when I am a little less tired. It is working great right now. I am really impressed with it. Thanks for the speedy reply and apologize if I wasted your time.

  4. #4 | Posted November 24, 2007 at 12:39 am

    Stephen, I got to step 5 in your Easy Setup instructions, but am stuck there. I have wordpress in /etc/wordpress, so I’ve moved the wp-config.php file there. I have my other wordpress files in /usr/share/wordpress. I currently have one blog, but want to set up a second. My first blog has the url dennistein.com/blog and I want my second one to have the url erivellino.org/blog Using Linux, I just use the ln -s command to make a symlink which I can point to /etc/wordpress. What folder to I put this symlink in?

    Step 6 says to go to each site, blogs through Five Minute Install. I thought the Virtual Multiblog idea was so that you don’t have multiple installs of WordPress on the same computer. I’m new at this… I’m hosting this on my own computer.

    Thanks for your help.

  5. #5 | Posted November 24, 2007 at 3:23 am

    [...] Nerdaphernalia » Virtual Multiblog for WordPress ???? ?????? ??? ???? ???? ?????? ????? ??? ????? ???. ?????? ?????? ??? ????? ???? ????? ??? ??? ?? ???? ?????? ???? ?????? ?????. (tags: wordpress multi-blogs hacks) [...]

  6. #6 | Posted November 24, 2007 at 12:08 pm

    Did not tried it yet, but just for the idea i nrrd to WOW !!

    I’ll try it this weekend hope all go well

  7. #7 | Posted November 27, 2007 at 5:35 am

    [...] you run more than one WordPress site? Virtual multiblog may be useful to you. It’s a very different beast to WordPress MU, but I’m going to [...]

  8. #8 | Posted December 6, 2007 at 2:12 pm

    Stephen, thanks for the great work.

    I set up multiblog as you outlined in the advanced setup instructions. As a test, I set up a symlink to the wordpress folder in http://www.mysite.com/dog and included only that one user in mb-users.php. I went to the http://www.mysite.com/dog and it launched me into the WordPress install, which worked perfectly.

    Then I created a second symlink: http://www.mysite.com/cat and edited mb-users.php to add that user. When I went to http://www.mysite.com/cat, I saw the page for http://www.mysite.com/dog. When I tried http://www.mysite.com/cat/wp-admin/install.php, I got the "Wordpress is already installed" message.

    Can you tell me where I’ve gone wrong?

    Thanks!

  9. #9 | Posted December 6, 2007 at 3:35 pm

    Dan –

    What exactly do you have in the vusers[] array? Where are the WordPress files installed? Where exactly do the two symlinks point?

  10. #10 | Posted December 6, 2007 at 3:55 pm

    Stephen–

    Thanks for the response.

    The document root for my website is /nfs/users/ayso/public_html

    I installed WordPress outside the document root in /nfs/users/ayso/wordpress

    In the file /nfs/users/ayso/wordpress/wp-content/multiblog/config/mb-users.php:

    $vusers[] = ‘www.mysite.com/dog’;
    $vusers[] = ‘www.mysite.com/cat’;

    My symlinks point to /nfs/users/ayso/wordpress:

    ln -s /nfs/users/ayso/wordpress /nfs/users/ayso/public_html/dog
    ln -s /nfs/users/ayso/wordpress /nfs/users/ayso/public_html/cat

    When I configured the first blog, database tables were created which were prefixed by "wp_mysite_com_dog_".

    –Dan

  11. #11 | Posted December 10, 2007 at 1:09 am

    Dan — Honestly, I’ve never even tested it with an “install in one place, site in another” setup . You’re the first person to ask about it!

    That VUSER and table prefix is correct for the “dog” URL. Off the top of my head I don’t know why the “cat” one would not work, but I’m not surprised, either….

    I’ll have to look into it. I’ve never done a setup like that, but it’s worth my looking at, I think.

  12. #12 | Posted December 10, 2007 at 6:00 pm

    Stephen–

    Ok, I did a fresh install and got some things working.

    I installed wordpress outside the document root as I described before, and created symlinks to it called dog and cat in the document root. Now http://www.mysite.com/dog and http://www.mysite.com/cat each show separate blogs. That is, everything works as advertised.

    For that, I say thank you and great job. That will make my job as webmaster easier.

    What does not work is if I try to add a blog at http://www.mysite.com/lizard/gecko.

    It appears that all the blogs have to be at the document root level. I see in mb_get_virtual_user() you use

    $mbroot = substr( $mbroot, 0, strpos( $mbroot, ‘/’ )

    to truncate everything after the first slash. So a blog in a subdirectory below the document root will not work. I’ve tried changing that as follows:

    if ( strpos( $mbroot, ‘/’ ) ) $test_mbroot = substr( $mbroot, 0, strpos( $mbroot, ‘/’ ) );
    if ( $test_mbroot == ‘wp-admin’ || $test_mbroot == ‘wp-content’ || $test_mbroot == ‘wp-includes’ ) $mbroot = ”;

    That allows mb_get_virtual_user() to return a user like mysite_com_lizard_gecko. But that is not the whole answer, and I’m trying to trace out the other changes that are needed.

    Am I going down a bad path trying to edit your code to work with blogs at different levels in the website? Is there a fundamental reason that blogs need to be on the document root level?

    Thanks for your help!

    –Dan

  13. #13 | Posted December 10, 2007 at 9:16 pm

    There’s nothing inherently _wrong_ with it, but it is dangerous….

    A setup allowing for lower nested blogs allows for some really screwy setups. If you put a directory “lizard” at the root, and then put a “gecko” symlink back to the root directory, you would also have /lizard/gecko/lizard/ (err… I think…). You might not even realize it, but if somebody else _did_ they could come along and literally set up another blog on _your_ site.

    I left out that ability because of the potential for mischief and error. So… go for it, but be careful you know _all_ the blogs you are creating….

  14. #14 | Posted December 10, 2007 at 9:28 pm

    Stephen Hi – this seems like an extraordinary tool.

    I’ve tried a few times to get it up and running, but each time I do, something very strange happens. The wp-login.php works just fine on both blogs, but for some reason the homepage for each is blank. I’m trying to install this for a school site that needs a second blog for displaying Spanish language content, so the setup i hope to build is as follows:

    A. One instance of wordpress, installed in the root at http://www.mitatlawrence.net.
    B. The base website, the English version, would just be http://www.mitatlawrence.net (this instance is already installed and has received some use).
    C. The Spanish version would be http://www.mitatlawrence.net/espanol .

    I believe i’ve successfully created the appropriate symlink. the site is hosted on godaddy, so i had to run a php command in browser, using the following:

    symlink (‘.’, ‘espanol’) ;

    It created a shortcut link in the root directory, so I’m assuming it worked.

    Then i followed the instructions for setting up the users, adding these:
    $vusers[] = ‘www.mitatlawrence.net’;
    $vusers[] = ‘www.mitatlawrence.net/espanol’;

    and finally dropped the new wp-config.php file in the root, with db info loaded.

    the result is that i visit each blog for the first time, and it runs through the set up. Then I’m taken to the dashboard, which works great. But for some reason, any time i try to go to the site itself after that, the pages turn up completely blank. Have tried a few different approaches, but each results in the same problem.

    Thank you very much for the plugin, I’m confident it will work. Any advice you may have is greatly appreciated.

    jase

  15. #15 | Posted December 10, 2007 at 9:29 pm

    Dan — Actually, I’m forgetting the full ramifications of why this can be problemeatic. (I saw things as I went, but didn’t keep track — I just didn’t pursue subdirectory blogs).

    I think you’ll be okay if you use the full directory $vusers[] (e.g. “www.mysite.com/dog” instead of “dog”). It gets very dicey with people who don’t use the mb-users file (that is “easy setup” could cause problems) or who don’t specify the whole domain/directory structure.

    I suppose i could go back in and add subdirectory ability _only_ if $vusers[] is used AND domain/directory is specified. I might just do this. Let me know if you figure it out, because I don’t think it’s terribly difficult, and you might already be on top of it. ;)

  16. #16 | Posted December 11, 2007 at 4:46 pm

    Jase — fix your markup and see if that fixes your problem. Invalid (X)HTML is a huge source of rendering mischief.

    W3C Validator report for your site

  17. jase
    #17 | Posted December 11, 2007 at 5:20 pm

    Strider thank you – i will look in to the markup. I checked validation of your site – striderweb.com, and the base site passes with flying colors. However, I checked out this particular page, and it has 11 errors -
    http://validator.w3.org/check?uri=http%3A%2F%2Fstriderw...

    Yet it seems that you have great success with the multiblog tool. Would there be any other reasons besides invalid xhtml that I’m getting blank pages from the multiblog tool? Perhaps I’m doing something wrong on the inputs or something.

    Thank you for the quick response and for the multiblog tool. I’m confident that i’ll get it to work for mit at lawrence and it will save the day.

    jase

  18. #18 | Posted December 11, 2007 at 6:28 pm

    Jase — thanks for pointing out a flaw in my markup.

    In answer to your question — there are millions (literally) of potential causes. Validating your HTML will reduce them by an order of magnitude.

    Incidentally, the validation of my own page is a completely moot point, as I am not having any rendering problems of which I know. The fact that you successfully ran the install for both blogs strongly suggests that the multi-blog system is working just fine, and that your problem lies elsewhere. Invalid markup is the most obvious candidate.

  19. jase
    #19 | Posted December 11, 2007 at 6:40 pm

    thanks for the quick response. Will try my best to clean up the code, though i am not a proficient coder like you so fixing all the errors may take awhile. Alternatively, it seems like the tool you developed works wonderfully with fresh installs of wordpress, so perhaps it would be the path of least resistance if i just start afresh with a new install. will give that a shot and report back.

    also regarding the validation of this page – everything here shows up wonderfully and the site is functional and aesthetic. as far as a lay user like me is concerned there are no flaws here.

    Thanks Stephen,

    jase

  20. #20 | Posted December 13, 2007 at 6:18 pm

    Stephen–

    When I said I got multiblog working as advertised, I was mistaken. I was actually back to the first problem that I had posted on December 6. Regardless of which blog I viewed, the first user in the vusers array was selected.

    I traced the problem down and had to make a modification to correct what I believe is an error in the code in order to get it working on a site with a url beginning with www.

    In mb_get_virtual_user you get the server name like so:

    $server = $_SERVER['HTTP_HOST'];
    $shortserver = str_replace(‘www.’, ”, $server );

    Then you get the current user to test against the vuser list like so:

    foreach($vusers as $curruser) {
    $curruser = str_replace(‘www.’, ”, $curruser );
    etc.

    Finally you test like so:

    $server . \’/\’ . $mbroot == $curruser’

    Since you’ve eliminated the www from the user names in the vuser array, I think you should use the $shortserver in your test (as you do in the remainder of the tests in the list).

    When I made that change, the program worked great. It is now up and running on http://www.ayso104.org/coachblog and http://www.ayso104.org/homeblog.

    (It worked fine on my laptop before the change, because the host name was "localhost", but on the ISP’s site, the host name begins with www.)

    So, what do you think? Was changing $server to $shortserver in that function the right thing to do, or does that create other problems that I don’t understand?

    –Dan

    P.S. (I’ve made a change for subdirectory blogs, as we discussed, but I’ve not tested it well enough to put into production yet.)

Pages: [1] 2 3 4 5 6 7 8 9 10 1135 » Show All

Post a Comment

Your email is never shared.

Subscribe without commenting