Kohana Virtual Hosts

If you intend to run multiple Kohana applications from the same code base, the separation of the system & modules directories from the application and it's themes is the standard way to go.

For most shared applications you'd develop the functionality and it's views as separate individual modules, while the only thing the application directory needs to hold are configuration files for separate databases and the theme-specific views of which there may only be one or two along with the cache & log directories.

The other overhead is maintaining Apache virtual hosts, setting up mod_vhost_alias which may not be possible if you don't rent a VPS or dedicated server. By making a few small modifications to your Kohana index.php file you can keep all your applications in a single directory and cut down the amount of admin stuff you have to do.

$kohana_application = $_SERVER['SERVER_NAME'];
if( ! file_exists($kohana_application) )
{
	$kohana_application = 'default';
}

If you have a dedicated IP address you can just point new domains to it and presto! it'll work as long as you have an application directory with the same name as the domain name. An example directory structure could be like:

kohana/                   # Kohana SVN trunk
modules/                  # Application modules
root/                     # Web root
|-index.php               # Kohana dispatcher
|-@harry2.example.com/    # Symlink to harry.exmaple.com
|
|-harry.example.com/
| |-cache/
| |-log/
| `-views/
|   |-header.php
|    `-footer.php
`-admin.example.com/
  |-cache/
  `-log/
    .. etc.    

Leave a Reply



About

Harry is a professional developer and sysadmin from London, UK.

He's an atheist, employed at PixelMags LLC, a socialist and has a pragmatic outlook on life, love and religion.

Bookmarks

I'm constantly finding interesting stuff, here are some of the things I've bookmarked recently:

HarryR on Faves.com