
This is the first in a series of posts on installing and using the Kohana PHP framework. For more in the series, see:
Part 2: Moving Kohana out of the docroot

Kohana is an open source, object oriented, MVC framework that originated as a fork of the CodeIgniter project.
For a long time, I’ve been a big fan of CodeIgniter, the PHP framework. I’m still a big fan. CodeIgniter is lightweight, fast, and has a short learning curve. The problem is that it’s dead in the water, see http://ellislab.com/blog/entry/ellislab-seeking-new-owner-for-codeigniter. After looking around at some other options, I’ve started putting Kohana through it’s paces. Kohana was originally a fork of CodeIgniter, although later versions have been rewritten from the ground up. So, first off the bat, there’s that shared ancestry, which should mean that a lot of my CodeIgniter knowledge will be directly translatable to the Kohana world. Kohana also keeps that commitment to being fast and lightweight. That’s important to me. A framework is a development tool. It should enable me to get something up and running quickly, but it shouldn’t be so heavy that it gets in the way. Kohana looks like a good option, so I’m going to take a look at what it takes to get something up and running.
Installing kohana is pretty straight forward. Go to http://kohanaframework.org/download to download the latest version. Unzip it and you’ll end up with a new `kohana` folder. Place the contents of that folder inside your web server document root. You should wind up with a directory structure like this:
Ignore the public/ directory in that last image. That’s part of the set up for ,y next post! Once you have the files in the right place, you’ll need to make a few edits to
1 | application/bootstrap.php |
. This file gets loaded by index.php and is responsible for getting everything loaded and in the right place. First, set the default timezone:
1 2 | // Example of changing timezone to Sao Paulo, Brazil date_default_timezone_set('America/Sao_Paulo'); |
Next, you’ll need to set the `base_url` to reflect the location of kohana relative to your document root:
1 2 3 4 5 6 7 | /** * Example of kohana's installation directly in docroot * Apache's DocumentRoot configured to /var/www */ Kohana::init(array( 'base_url' => '/', )); |
Finally, you’ll probably need to chmod the `application/cache` and `application/logs` directories to make them writable by the application:
1 2 | sudo chmod -R a+rwx application/cache sudo chmod -R a+rwx application/logs |
Once you’ve done all that, just open your url in a browser, in this case, http://locahost/, and you should see something like this:
If the installation tests report any issues, you’re on your own getting those fixed. Once Kohana’s environment checks all report green, either delete or rename the install.php file. Once that’s gone ( or at least renamed ) then when you reload the page, Kohana will route to the default Controller, and you’ll see a page that says ‘hello, world!’.
From here on out, it’s pretty straight forward. Kohana is a Object Oriented framework that assumes a Model-View-Controller architecture. Creating an application is a simple matter of defining routes, and creating controllers, models and views. In my next post, I’ll go into more detail on how to create a real working application using Kohana.