Kohana: under the hood (index.php)

To help some people understand Kohana a little better I’d like to discuss some of the things happening under the hood. We start of with the index.php file which is where everything Kohana begins.

Index.php
The first thing that’s done is setting where the Kohana application and system files are stored. Normally you don’t need to touch this but if you want to move the application and system files out of the webroot you have to.

Example of Kohana out of the webroot

+- http_docs
| +- index.php
+-application
+-system

With this setup you have to change the $kohana_application and $kohana_system variables in index.php or the right files can’t be included.

$kohana_application='../application';
$kohana_system='../system';

Similarly you can have multiple applications pointing to the same system directory to make updating your applications easier.

There is another variable to determine the modules directory. You’ll see it again when configuring modules in application/config.php

Next comes setting the error reporting, you can find more information on this in the php.net documentation.
Kohana then defines which extension all files will use. Default is .php but you can change this to .php5 for example if your hosts supports this. Note that you’d have to rename all files to a .php5 extension.

The index.php file continues with defining some constants used through Kohana (DOCROOT, KOHANA, APPPATH and SYSPATH). At the end the bootstrap file is included and Kohana is launched. The bootstrap will be covered in the next post.

Leave a Comment