Horde 3.2: Serving multiple subdomains with one installation

Horde has a lot of applications. Many sites run quite a few of them, and some people have asked about running subdomains for different parts of horde - for example, using http://mail.example.com/, http://calendar.example.com/, and http://photos.example.com/ from the same installation.

Well, with Horde 3.2 (RC3 and later), http://wiki.horde.org/, http://bugs.horde.org/, http://cvs.horde.org/, and http://dev.horde.org/ all now run from the same Horde installation with no conditionals in the configuration files. Here's how:

1. Set cookie_domain

For authentication and sessions to persist for each subdomain, your cookies must span each subdomain. In our case we want cookies to be valid across all of horde.org, so we configure cookies as:

$conf['cookie']['domain'] = '.horde.org';
$conf['cookie']['path'] = '/';

Note the '.' (period) before horde.org in the domain setting - cookie domains must have two dots in them. 

2. Set application webroots

Normally Horde applications have their webroot - the base path for any URLs for the application - set relative to Horde's webroot. In this case, we want the webroots to be set directly to the application's subdomain:

$this->applications['chora'] = array(
    'fileroot' => dirname(__FILE__) . '/../chora',
    'webroot' => 'http://cvs.horde.org',
    ... 

This will ensure that all paths for Chora begin with http://cvs.horde.org. Do the same thing for any other application you want rooted to a subdomain.

3. Set Horde's webroot

Horde itself must be available to all of these applications as it provides most of the CSS, images, and services such as log in/log out, help, and preferences. You could give Horde an absolute webroot as well. For dev.horde.org,  we've chosen to use Apache Alias directives to provide Horde in every subdomain. The Apache configuration for that is:

    Alias /h/ "/path/to/horde/"

And the registry.php configuration for Horde then looks like:

$this->applications['horde'] = array(
    'fileroot' => dirname(__FILE__) . '/..',
    'webroot' => '/h',
    ...

We use /h instead of /horde so that http://cvs.horde.org/horde/  is rewritten properly to show the horde module in our CVS repository. If we ever have an application called h, we'll have to figure something else out.