How to Use Habari to Run Multiple Sites - Sag Rising
Notes to Myself

How to Use Habari to Run Multiple Sites

Posted by Richard Cockrum on February 25, 2008

One of the reasons I started looking at Habari was it's promise to be able to host multiple sites on one installation of the software. If you have multiple sites, that can save a fair amount of space on your server, and it makes upgrading much easier. Install the updated software once, and all your sites are automatically updated.

According to Habari's manual:

In order to run multiple sites, you will first need to create a sites directory inside your user directory. Then, inside user/sites you will create a directory for each site you want to run. Inside each of these sub-directories you will place a config.php with that site's configuration directives.

...
Additional Habari-powered sites do not need to use the same domain. Provided the web server is properly configured, a single installation of the Habari source code can serve www.habariproject.org, www.habarithemes.org, and www.habari-ya-kazi.com. Likewise, sub-domains and sub-directories are also supported.

Each Habari site can use its own themes and plugins, as well as the themes and plugins available to the "main" site. Simply create /themes and /plugins sub-directories inside each site's directory. A theme or plugin located in a site's directory structure is only available to that site; while themes and plugins in the top-level /user directory will be available to all sites.

I found two problems with this, though.

First, sub-directories don't work properly yet. So if your main site is www.example.com, www.example.com/subdir won't work properly.

Second, it took a while to figure out what properly configured means. In the end, it turned out to be simple.

Let's say your site's url is www.example.com. The top level directory structure for a Habari installation will look like this:

  • www.example.com
    • 3rdparty
    • doc
    • system
    • user
To enable multiple sites, create a sites directory within the user directory. Within the sites directory create a directory for each site you wish to have. The only limitation is that the site's directory needs to have the same name as the url of the site. For example, if you want to run another two sites called www.sitetwo.com and test.example.com, the user directory structure will look like this:

  • user
    • sites
      • www.sitetwo.com
      • test.example.com
In each of the sub-directories, place a config file with that site's configuration directives. You can use any combination of MySQL or SQLite databases, any themes, any plugins. All the sites are independent. Each site can even have it's own private themes and plugins that aren't available to the other sites on the installation by creating a themes and a plugins sub-directory for the site like this:

  • www.sitetwo.com
    • themes
    • plugins
and placing your themes and plugins there. When it is looking for the proper themes and plugins, Habari looks first in the site's private directories, then in the installation's user directory, then in the installation's system directory.

After you have your directories set up, you need to tell the webserver how to find the sites - the properly configured part the manual talks about. This turns out to be simple. Point the web server to the same directory the main site is in. In other words, with the examples I've used here: If your main site is www.example.com and it is at /home/www, tell the web server that www.sitetwo.com, and test.example.com are also at /home/www. Habari will find the sub-directory with the same name as the url, and use the config file in that directory to pull up the site.

It Just Works.



4 Responses to How to Use Habari to Run Multiple Sites

  • Looks like good stuff to add to the wiki :)

    There is likely to be some effort in upcoming releases to make multi-site Habari more robust and scalable.

  • I'll take that as a hint, Michael. :) I thought about it, but my experience with how multi-site setup works varies from the way it's supposed to work. Taken for what it is, it works well. I'm running mirrors of four sites on one installation of Habari locally.

    I didn't want to step on anyone's toes by changing the wiki from the way Habari is supposed to work, since I thought it would be fixed, to the way it actually does work.

    Multi-site is an important feature for Habari. I look forward to support for it being improved.

    #41 | Comment by rick on February 26, 2008 3:09pm
  • In that case, a post to dev outlining the differences between the documented way it works and the actual way it works would be a great start to kickstarting development. But I'm not trying to make you do work, I haven't even experimented with multi-site myself yet :)

  • Okay ( to a post on -dev).

    I wouldn't know how to make it work, myself. I've looked at the code in Site.php . I've looked at the comments around the ticket about subdirectory sites not working. Most of the code I don't understand and wouldn't want to mess with. I can't see why it doesn't work as it's supposed to.

    #57 | Comment by rick on March 12, 2008 7:20pm


What do you think?


Subscribe

More Posts

Recent Comments

Tags