Choosing and configuring the engine for mertner.com

When Morten and I decided to “do something” about our web site several months ago, we went through lots of thoughts. A full-blown CMS system is quite heavy and probably requires more customization than we want, but the blogging engines were mostly a bit too primitive.

Admittedly, our requirements were probably not standard ones. We wanted to
* have a nice home page for each member of the family
* have somewhere to show site news and updates
* have a place to put static stuff like a CV, contact details, etc
* use a system that doesn’t rely on frames or tables but uses CSS for layout
* make sure it was easy to use. We probably won’t blog very often.
* use something customizable so we could change the look and feel and also make use of plug-ins, perhaps write a few ourselves.
* use something Free (i.e. paying for it was OK, but not proprietary)
* have multiple blogs so each person can have his or hew own blog


After a lot of research, which included looking extensively at [this site](http://www.asymptomatic.net/blogbreakdown.htm), we decided that [WordPress](http://www.wordpress.org) might fit the bill. The only problem is that it only supports a single blog per installation, and we didn’t want to install several copies of the software since we would invariably forget copying a few files now and again.

Since the site runs on Linux, we decided to go for it anyway and try to set up virtual directories for each user, all pointing to the same installation. This way, any change to any of the files would immediately be reflected for all sites.

With this approach, the first hurdle to overcome is to ensure that each virtual WordPress instance uses its own database. At this point, I decided I might have to learn a bit about PHP. Fortunately it’s quite easy, so the story doesn’t end here 🙂

The default installation uses a file named wp-config.php to store this information – a hack to choose a different setup based on the URL prefix was required. I copied wp-config.php to config-default.php and replaced wp-config.php with code to do just that. Download it [here](http://www.mertner.com/sitecode/wp-config.phps).

The interesting lines in this file are reproduced here:

require( dirname(__FILE__) . '/wp-includes/my-functions.php' );
$configfile = '/config-default.php';

$user = get_virtual_user();
if ($user != "/") {
  $configfile = '/config-' . $user . '.php';
}

The get\_virtual\_user function is defined in [my-functions.php](http://www.mertner.com/sitecode/my-functions.phps) and performs URL matching to return the name of the current user. This is then used to choose the right config file – and each config file contains similar settings but a different database table prefix. This way, all sites use one database but do not share tables between them.

[my-functions.php](http://www.mertner.com/sitecode/my-functions.phps) also includes a new function that I call in index.php. The print\_virtualuser\_list function emits links for each of the virtual users to allow a nice menu for switching between user blogs to be displayed at the top of the page. This is a snippet that I put before The Loop in index.php:

<ul id="navlist">
 <?php print_virtualuser_list(); ?>
</ul>

A few other edits in index.php were required to make the site contents just right: I don’t want a calendar so it was axed, and IE is truly horrible at almost everything so I use [FireFox](http://getfirefox.com) instead and added a link to get it in the meta section when an IE user browses the site.

For more info, have a look at these related posts:
* How to add another user to the multi-user blog
* How to make Fake Folders work with a multi-blog setup
* A plugin-related caveat to consider

44 thoughts on “Choosing and configuring the engine for mertner.com

  1. I read this with interest! I’m looking for a way to make WP multi-blog myself (for use with my class). If I understand correctly, your solution doesn’t allow the different weblogs to “customize” their index.php or stylesheet, does it?

  2. The approach I have taken means that everything is shared between all the users – this was after all what I wanted 🙂 However, if you want to “branch” a user, you could simply create a real directory in place of the symlink and copy all the files to that dir.

    Alternatively, you could make edits to index.php that switch based on the current “user”. This would be easy to do, but could end up as a very messy solution if you make many changes…

  3. Pingback: Just Another Ant

  4. Is each user only allowed to edit their own blog, or can some users edit each blog. I am in the process of setting up a free resource for interaction designers and I see that I will need to have multiple blogs, one blog for each section – however there initially will be two to three users publishing to each blog. Drop me a note if you have time, I have a few questions!

  5. Each blog has its own database, including its own user database. For the users that need to write to all of the blogs, I have just created the same user for each blog – since they all have the same name, nobody can tell the difference.

    It would be possible to get fancy and modify the code to do user management in a master database, but I haven’t done this.

  6. After reading your “How to add a new user” it became clear how you did what you wanted. I’m working on the same thing, but I’ve gone down the mod_rewrite route with little success. I think I’ll givey our simlink idea a go!
    You might be interested in my work getting Smarty and WP talking together. You could store your templates in a seperate per-user directories, and all you have to do is point Smarty at that user’s directory to have a completely different template!

  7. Working on a wordpress site for myself, and ran into an issue with your virtual user code. I changed all occurences of the global $users to $vusers and no longer have the problem. I am running WP 1.2 as distributed by Debian.

  8. Thanks for the hint; perhaps something clashes with the name. I have updated the code to use $vusers instead.

  9. Hi

    I was browsing the net looking for some solutions to set up my own blog page with other php pages like forum and picture gallery.

    Then i came over your page and found that the way you had set this up is some what close to how i would like to do it.
    Anyway, since i was here i thought i could read some of your blogs to see what was on here and i read this one and was thinking mayby you would have a interest of knowing about the software i use for my blog page.
    If you are looking for a Multilingual, multiuser, multi-blog engine i will advice you to check out http://b2evolution.net. Other php software i use is phpbb (http://www.phpbb.com) for forum and coppermind (http://coppermine.sf.net) for picture gallery. They are all open source software and free of charge.
    I run them all on my debian linux with apache2, php4 and mysql, the best part is that they are fairly easy to install and manage.

    Hope you find this information interesting!

    PS.
    If you have any tips on how i can set up all my php sites with only one user database i would realy like to know about it!!
    I’m pulling my hair and abusing google to find out how to do this.

    Have great day and a happy easter.

    Regards
    Kenneth (Norway)
    It’s nice to be important, but it’s more important to be nice.

  10. This was really helpful advice!

    Unfortunately I’ve run into some problems with permalinks, since there is only one .htaccess file for all the blogs.

  11. I found the culprit. It was the wpLicense 0.5.2 plugin. Apparently it adds an icon image to the Options menu, which causes your plugin to break. Remove the img tag in the wpLicense plugin solves the problem. Thanks Ozh for the nifty plugin! http://www.umutbilgisayar.com.tr umutforum.com

  12. Awesome, awesome, awesome.

    I’ll try to get this going on my site. It would be nice if you put up a page with a more step-by-step set of instructions, but I think I’ve figured it out.

    I’ve been thinking of converting some of the “non blog” sections of my site to a blog format.

    I checked out several different approaches to multi-blog WordPress, and the nice thing about your approach is that it is a very elegant concept that will easily adapt to later version of WordPress (assuming it continues to use a specific config-only file). I’m guessing that it won’t actually need any change at all. (Did you originally write this for 1.2 or something? Just proves my point, I suppose!)

    Anyway, the new blog section I’m planning is a web design blog, and I’ll be sure to put a good rundown of yoru emthod in there.

    Good stuff!

  13. For Steph who (way back when) asked about different stylesheets and such for various blogs — this method of multiblog allows for totally different settings for different blogs, which means that it will quite happily apply different templates to different blogs.

    Might be a pain for only minor differences when you want the rest aligned, but in the end you can do totally different appearances for different blogs.

    I’ve only tested this on my local machine so far, but in the next day or so I will do a “live” test, and it will be interesting to see how well it deals with the various plugins and such that I run.

    As I said before, this is actually such a straightforward and clean hack that I don’t really anticipate problems. None of the plugins I use require changes to default files. Heck, the one plugin I used that required me to add a file to the main directory I modified to allow me to put all the files in the plugins folder. Actually, I will probably edit this one a bit so all files other than wp-config.php go in wp-content/multiblog or somesuch.

    I think this is a good idea because it makes updating the blog version later much easier. wp-content stays, config stays, everything else gets deleted and the new files copied in.

  14. Works fine. Thanks a lot for your work 🙂

    I had to change

    $_SERVER[‘PHP_SELF’] to $_SERVER[‘HTTP_HOST’]

    in my my-functions.php.

  15. Having your own server with WordPress on it, can be realy entertaining. Installing it can be quite learning unless you want to keep everything standard.

  16. I read it, including comments, before figuring out yet another hack for single and, or shared WordPress installation to host multiple blogs for virtual users and, or virtual domains.

    And, IMHO, it is quite smart a trick which has solved my purpose well, plz check Yet another WordPress hack to host virtual users.

    Regards,

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

  18. Pingback: Nerdaphernalia » echo “Hello Again, World!”;

  19. Hi Allan,

    We have the same name! Actually, my middle name is Allan. I have been trying to get multiblog to work unsuccessfully for about a week and could really use some advise. I have configured everything as outlined in the readme, but when I go to any user other than the default, it just list the directory. You can see at http://www.fittwarehouse.com/blog then a user at http://www.fittwarehouse.com/mark

    Any suggestions you have would be GREATLY appreciated!

    Thanks in advance,

    Mark

  20. Pingback: Comment on Choosing and configuring the engine for mertner.com by bsd

  21. WordPress MU, short for Multi-User, is a WordPress version that you probably have used without really knowing it. Automattic’s hosted blog service, WordPress.com, uses WordPress MU, although what you get when signing up with WordPress.com is pretty far from your basic WordPress MU install. WordPress Mu multiple ping services are easy to set. Go to your admin interface. Click the ‘Site Admin’ menu. Click the ‘Blogs’ submenu. Then click the ‘Edit’ link next to 1 of your blogs. You will now see the ‘Edit Blog’ page. Scroll down a bit and you will see the WordPress Mu ‘Ping Sites’ edit box (textarea). Add your ping services list there and hit the ‘Update Options’ button. All finished. Now you have your WordPress Mu blog setup to use multiple ping services.

  22. Pingback: Installing Multiple Blogs

  23. Pingback: Multiple Wordpress blogs. One install. | *shrug*

  24. Pingback: RodeWorks » WordPress MU Disillusionment

  25. Now that is truly fantastic…
    I have seen a fair few WordPress hosting scripts about though to take this approach is a much more direct and easy approach to it.

    Only problem is I suppose is that if one user was to install a theme then that theme would be viewable by all users. The same would apply to plugins and there modules, so they I suppose would have to be individual from the rest, thus requirng a fair bit more work, though I can start to fathom it out in my head already.

    Karl

  26. Pingback: IN portal » How to: Installing Multiple Blogs

  27. Pingback: En.nicuilie.eu Blogs » How to: Installing Multiple Blogs

  28. Pingback: WPMU is out, Virtual Multiblog is in | Hackadelic

  29. Hi, i am new to blogging and programming. I am trying to set up an online magazine and i am confused about how all of this works. So i will tell you what i am trying to do and maybe you can give me some direction.
    I want to have about 8 blogs that are their own sections with specific content.
    I want the main/front page to show the most recent posts from each of those sections.
    I know i am going to have one database and each config file will have a different table in the database.
    And i want all of the blogs/ sections to have the same look. Would i just do that with a CSS that controls all of them?
    And how do i get the post to show up on the main page?

    Any help will be greatly appreciated.

  30. Pingback: 2nd Hand Blog » Blog Archive » New Post 2

  31. Pingback: mertner.com/allan » Blog Archive » Choosing and configuring the engine for mertner.com | Squico

  32. This all seems rather mysterious. The links to examples inside this blog are missing. Like this one: Download it [here](http://www.mertner.com/sitecode/wp-config.phps)

    What am I missing. I have a site that already has 3 subdirectories and I can’t edit from within the WP Adim for all 3 – can’t see but the main one. Have to edit every little thing 3 times via ftp to make any changes throughout the site and I know there has to be an easier way. It seems odd that this thread is so old and yet no one can seem to really dial this in. Allan, you must be a genius, do you offer services for pay to help?

  33. Hello pal,
    I Read Your Stuff. I need a particular thing , in which a single installation have Multiple Blogs. From Your Article I think it’s Possible . Am I Right? Also I can use Multiple Templates in the same Blogs ….. I believe that need only Change the Template in Admin panel. So I Expect Your Fast Reply. What Type of Changes I need to give in my wp-config.php
    file. Please give a complete idea For Solution… I am waiting Your Good Reply…

    Regards
    Anes P.A

  34. Hi, I have hosting on One.com and I need to use WordPress and subdomains.

    To create subdomain sub1.example.com I just need to create folder /sub1 with index.html in it. I need several subdomains, means several folders, but I need them to be managed from single WP database. Is that possible?

  35. Pingback: Příspěvek 10 | LMS a LCMS elea.cz

  36. Alternatively, you could make edits to index.php that switch based on the current “user”. This would be easy to do, but could end up as a very messy solution if you make many changes…

  37. Radim: Consider to create only folders /sub1 …. with a subdomains it can take longer to get SEO rankings.

  38. Pingback: Mrasnika’s Lair » Funky caching in WordPress + nginx/php-fpm without any plugins

Comments are closed.