Home > Uncategorized > Setting Up Kohana Development and Production Environments

Setting Up Kohana Development and Production Environments

I develop my Kohana applications on Windows using the awesome XAMPP package. This allows me to test everything on my local PC before pushing the changes to the live server. Kohana uses an ‘IN_PRODUCTION’ constant which can be useful, especially for those little things that change. For example, I change the background colour of the page or header graphic so it’s obvious to me which environment I’m looking at. There’s nothing worse than pushing a page to the live server and then having to scramble around to find an old copy to replace it with. For this reason, I also recommend adding Subversion into your regime. It will save you a lot of panic attacks, trust me.

There are also five other settings that you should change within Kohana to ensure everything works correctly across environments.

.htaccess

RewriteBase /
RewriteBase /www.mydomain.com/

A production site will need the top RewriteBase command. A development site will need the bottom command if your URL is http://localhost/www.mydomain.com/ unless you’ve gone to the extra effort of creating virtual hosts for every site you’re working on.

index.php (Front Controller)

define('IN_PRODUCTION', (strpos ($_SERVER['SERVER_NAME'], 'localhost') === FALSE));

This piece of PHP magic will set the IN_PRODUCTION constant correctly by looking for localhost in the server’s name, assuming you haven’t changed the name of your server anyhow.

/application/config/config.php

$config['domain'] = IN_PRODUCTION ? 'www.mydomain.com' : '';

This will ensure that the correct domain is setup and that your URLs are routed correctly in Kohana.

/application/config/config.php

$config['log_threshold'] = IN_PRODUCTION ? 1 : 4;

This changes the log threshold based on the IN_PRODUCTION, so you only log the important events on the production site but log everything in development.

/application/config/cookie.php

$config['domain'] = IN_PRODUCTION ? 'www.mydomain.com' : '';

This last piece avoids any problems with browsers, such as Firefox, that don’t like setting cookies on localhost. If your browser doesn’t accept the cookies the session handling in Kohana will also fail, effectively not carrying it over from one page to the next. It took me a while to work out what the cause of this problem was.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: