Musings on a Multiblog WordPress

[fr] Je réfléchis à comment on pourrait donner à WordPress la capacité de gérer plusieurs blogs avec une installation. Je me heurte à un problème concernant les includes PHP. Feedback et autres idées bienvenues!

Update June 2007: Try WordPress Multi-User now.

I’ve used Shelley’s instructions using soft links. I tried Rubén’s proof-of-concept, but got stuck somewhere in the middle.

So I started thinking: how can we go about making WordPress MultiBlog-capable? Here is a rough transcript of my thoughts (I’ve removed some of the dead ends and hesitations) in the hope that they might contribute to the general resolution of the problem. I have to point out my position here: somebody with a dedicated server who’s thinking of setting up a “WordPress weblog-farm” (for my pupils, mainly). So I’m aware that I’m not the “standard user” and that my solution is going to be impractical to many. But hey, let’s see where it leads, all the same. Actually, I think I probably reconstructed most of Rubén’s strategy here — but I’m not sure to what extent what I suggest differs from what he has done.

From a system point of view, we want to have a unique installation of WordPress, and duplication of only the files which are different from one blog to another (index.php, wp-config.php, wp-comments.php, wp-layout.css, to name a few obvious ones). The whole point being that when the isntall needs to be upgraded, it only has to be upgraded in one place. When a plugin is downloaded and installed, it only has to be done once for all weblogs — though it can of course be activated individually for each weblog.

From the point of view of the weblogs themselves, they need to appear to be in different domains/subdomains/folders/whatever. What I’m most interested in is different subdomains, so I’ll stick to that in my thinking. (Then somebody can come and tell me that my “solution” doesn’t work for subfolders, and here’s one that works for subfolders and subdomains, and we’ll all be happy, thankyouverymuch.) So, when I’m working with blog1.example.com all the addresses need to refer to that subdomain (blog1.example.com/wp-admin/, etc); ditto for blog2.example.com, blog3.example.com, blogn.example.com (I used to like maths in High School a lot).

As Rubén puts it, the problem with symbolic links (“soft links”) is called “soft link hell”: think of a great number of rubber bands stretched all over your server. Ugh. So let’s try to go in his direction, for a while. First, map all the subdomains to the same folder on the server. Let’s say blog1.example.com, blog2.example.com (etc.) all point to /home/bunny/www/wordpress/. Neat, huh? Not so. They will all use the same wp-config.php file, and hence all be the same weblog.

This is where Rubén’s idea comes in: include a file at the top of wp-config.php which:

  1. identifies which blog we are working with (in my case, by parsing $HTTP_HOST, for example — there might be a more elegant solution)
  2. “replaces” the files in the master installation directory by the files in a special “blog” directory, if they exist

The second point is the tricky one, of course. We’d probably have a subfolder per blog in wordpress/blogs: wordpress/blogs/blog1, wordpress/blogs/blog2, etc. The included file would match the subdomain string with the equivalent folder, check if the page it’s trying to retrieve exists in the folder, and if it does, include that one and stop processing the initial script after that. Another (maybe more elegant) option would be to do some Apache magic (I’m dreaming, no idea if it’s possible) to systematically check if a file is available in the subdirectory matching the subdomain before using the one in the master directory. Anybody know if this is feasible?

The problem I see is with includes. We have (at least) three types of include calls:

  • include (ABSPATH . 'wp-comments.php');
  • require ('./wp-blog-header.php');
  • require_once(dirname(__FILE__).'/' . '/wp-config.php');

As far as I see it, they’ll all break if the calling include is in /home/bunny/www/wordpress/blogs/blog1 and the file to be called is in /home/bunny/www/wordpress. What is wrong with relative includes? Oh, they would break too. Dammit.

We would need some intelligence to determine if the file to be included or called exists in the subdirectory or not, and magically adapt the include call to point to the “right” file. I suspect this could be done, but would require modifying all (at least, a lot of) the include/requires in WordPress.

Maybe another path to explore would be to create a table in the database to keep track of existing blogs, and of the files that need to be “overridden” for each blog. But again, I suspect that would mean recoding all the includes in WordPress.

Another problem would be .htaccess. Apache would be retrieving the same .htaccess for all subdomains, and that happens before PHP comes into play, if I’m not mistaken.

Any bright ideas to get us out of this fix? Alternate solutions? Comments? Things I missed or got wrong? The comments and trackbacks are yours. Thanks for your attention.

Similar Posts:

This entry was posted in Wordpress and tagged apache, change, farm, folder, hack, htaccess, modify, multi, multiblog, multiple, multisite, server, site, subdomain, Wanted, weblog, Weblog Technology, Wordpress. Bookmark the permalink.

50 Responses to Musings on a Multiblog WordPress

  1. eBlog says:

    ASA WP is multiblog I’ll run it.

  2. Pingback: Netlex News

  3. Donncha says:

    I’m working on multi blog support and also on getting Smarty into WP too. Smarty is almost working fine, without caching, but the multi-blog stuff is hard if you want to run all the blogs on one host. I went for the “thin layer” solution – mod_rewrite rules break up the URL and change URLs so that a “wpblog” variable is set to the name of the blog. A stripped down wp-config includes a wp-blogs/BLOGNAME/wp-config.php and then processing continues. Unfortunately, I’m not an expert at writing mod_rewrite rules and it’s proving to be a stumbling block. In b2++ I redirect all requests to a redirect.php, but that turned out to be a very complex solution – I needed lots of PHP code to figure out what the URL contained. I’d rather have a thin layer any day!

  4. Donncha says:

    I'm working on multi blog support and also on getting Smarty into WP too. Smarty is almost working fine, without caching, but the multi-blog stuff is hard if you want to run all the blogs on one host.
    I went for the “thin layer” solution – mod_rewrite rules break up the URL and change URLs so that a “wpblog” variable is set to the name of the blog. A stripped down wp-config includes a wp-blogs/BLOGNAME/wp-config.php and then processing continues.
    Unfortunately, I'm not an expert at writing mod_rewrite rules and it's proving to be a stumbling block.
    In b2++ I redirect all requests to a redirect.php, but that turned out to be a very complex solution – I needed lots of PHP code to figure out what the URL contained. I'd rather have a thin layer any day!

  5. CaptSolo says:

    Considering multi-blog setup, you should look at the b2evolution.

    It is an advanced blog engine, based on b2/cafelog – the same roots as WordPress.

    In b2evolution the multi-blog feature is included by default and it has been there for some time already. There is also a fine-grained access control per user/blog/operations – you may enable one user to have full access to one blog and no access to other (for example).

    Main developer’s blog (Francois Planque blog) is a fine example of a multi-blog. It also has UTF-8 support, skins (may be different for each blog), hierarchical categories.

    This does not imply you absolutely have to use b2evolution – but even if implementing multi-blog in WP, you may see how it works in b2evo. :)

  6. essdsm says:

    The b2Evolution solution doesn’t appear to be a scalable solution because human beings still have to create multiple blogs. Work in an institution with thousands of students and it just don’t work. In essence we want to take some basic details either from direct user entry or pulled in from authentication/authorization systems and then autogenerate the blog instance, a la Blogger.com

  7. birdboot says:

    Did you ever get any further with this? I would like to implement a multiblog solution which enables authenticated users to automatically set up blogs. LDAP authentication would provide all the information needed to do the setup.

  8. hbee says:

    As to B2E, I’d be fairly careful. I used the multiblog option to separate content and it works very nicely – BUT - 1) dealing with comment spam was a nightmare since 25% of the time the antispam tool denied me access the antispam page. 2) simple linking frequently took forever to work correctly (In fairness, I never took the time to troubleshoot these two issues, so who knows why it happened) 3) B2E takes up an awful lot of server load. My webhost (spookymedia.com) told me that several hosts refuse to allow users to run it. Her solution was a server accelerator that worked by using my own bandwidth to cache pages. Thus, using B2E cost me about an eighth of my bandwidth. It was good motivation to move me to WP, though.

  9. Pingback: 59 Ideas » Blog Archive » links for 2006-02-18

  10. Pingback: Chris Brunner .com

  11. Pingback: Weblog Tools Collection

  12. Pingback: Wordpress: Installing Multiple Blogs | A Blog you can use

  13. Jose Alfredo Muñoz Longinos says:

    I have some questions about of Wordpres MU. How to install on Windows 2003 server for multiblogs. I don’t have experience with blogs.

  14. turox says:

    There’s a way to install multiple blogs in different folders (/domains/www/domain1.com, /domains/www/domain2.com, /domains/www/domain3.com) using separated databases?

    I mean, an automatic installation, I have to install 1,000 WP blogs :( for a customer and I only have 40 blogs installed…

    any advice?

    thanks,

    Turox

  15. turox says:

    of course, i have full access to the server (mysql admin, root password, etc)

  16. turox says:

    i was trying to create a php script to do this, but just got stuck :’(

  17. Stephanie says:

    You should probably try http://mu.wordpress.org/ is you have 1000 blogs to set up…

  18. Umesh says:

    Setting up multiple blogs using mu.wordpress.org is fine but what I am looking for is a common user database. I want user authentication to be the same across all blogs. How can we do that in mu.

  19. Pingback: IM2 | OQP » Ferme de blogues avec Wordpress

  20. 59 Ideas says:

    3 years down the road and still some hacking required …

  21. Surya says:

    Thanks for your guide and information,

    I’ll create multiple blog in my domain, Now, I got the guide

    thanks

  22. Pingback: Thorsten´s Blogosphere » Blog Archiv » multiple Wordpressblogs for a weblog farm

  23. Pingback: Tonight at The smart way to web design and development in 2008

  24. Velia Pola says:

    I am hoping someone can advise me as to how to install Worpdress MU on the same url (or a subdomoain?) as my existing WordPress site. I want to keep my basic existing site on MU but set up a member/sitename area with MU. My MU installation defaults to a 404 page. Can the two programs co-exist? Any help would be appreciated.

  25. Velia Pola says:

    Sorry, I meant keep the existing site with WordPress, but have the members blogs on MU

  26. test says:

    test

  27. King James says:

    Wondering if this info still applies?

    I found this thread: http://wordpress.org/support/topic/can-i-run-multiple-blogs-off-one-wp-installation – most users say its impossible, but one guy in there said how to do it, but not really specifying how to change the MySQL database info for each site.

    Wondering if anyone knows how to have 50 or more WordPress blogs (each with different domains, and each with its own unique MySQL) on a server but have it point to 1 install?

  28. King James says:

    Oops, referred to wrong thread: this one: http://wordpress.org/support/topic/multiple-blogs-one-install the guy midway down talked about how he does it, but again, lacks info.

  29. WordPress now does multi-user out of the box.

  30. Pingback: Installing Multiple Blogs | Wbcom Designs INC