Tag Archives: php

Use Composer with Kohana 3.3

Kohana 3.3 has a file named “composer.json” in the root of the project, however it is not configured for Kohana and Composer is not installed.

This example is tested on a Mac. Windows users will need to install Composer from the instructions on the Composer project site, at http://getcomposer.org/doc/00-intro.md.

Install Composer

First, modify composer.json to tell composer where to install libraries.


	"config": {
		"vendor-dir": "application/vendor"
	"require": {
		"phpunit/phpunit": "3.7.24",
		"phing/phing": "dev-master"

Open a terminal and navigate to the root of your Kohana project.

curl -sS https://getcomposer.org/installer | php
php composer.phar install

Modify Kohana’s bootstrap.php File

Add this to bootstrap. Right above the router configuration is a good spot.

 * Autoload composer libraries
require APPPATH . 'vendor/autoload.php';

Adding a Library

You can either edit composer.json with your required library (and then re-run the install command above), or use the composer require verb from the command line to add the library, which also modifies composer.json.

php composer.phar require "monolog/monolog" "1.6.0"

The monolog package page is https://packagist.org/packages/monolog/monolog. Note that you need the package name for the first parameter and the version for the second parameter.

XAMPP on Mac OSX with Virtual Hosts

XAMPP is an all-in-one LAMP development solution for multiple platforms. I use Linux on my main computer and OSX for my laptop.

I’ve selected XAMPP to provide the LAMP environment on my Mac. It is free, in on-going development and works well.

Because I have several projects in development at once, I need to be able to quickly update my Mac with the current state of a project and then develop and test. Subversion is part of that equation and Komodo IDE is too. Setting up LAMP on Linux is a snap, but installing everything on the Mac, even with MacPorts would be tedious. There are a few pre-packaged solutions, including XAMPP, MAMP and Zend Server. I chose XAMPP after a little research and it has worked well for me.

The Apache virtual server does not come enabled by default, so a little setup is needed.

Folder for virtual websites

Create the folder “www” in your home directory, this example is in Terminal:

cd ~
mkdir www

This is the folder where you will place each of the virtual site directories. You could just as well put this somewhere else, but a “www” directory here makes sense to me.


Add the following to /Applications/XAMPP/etc/httpd.conf

	Options Indexes FollowSymLinks ExecCGI Includes
	AllowOverride All
	Order allow,deny
	Allow from all

In the above you will need to substitute your username for “yourusername”. This simply sets some Apache settings for the folder where your virtual sites will be.

In this same file find:

# Virtual hosts
#Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

…and un-rem out the Include line. This enables virtual hosting. Yay!


For each website, add a code block to /Applications/XAMPP/etc/extra/http-vhosts.conf

    DocumentRoot "/Users/yourusername/www/www.yourwebsitename.dev/public"
    ServerName yourwebsitename.dev
    ServerAlias www.yourwebsitename.dev
    ErrorLog "/Users/yourusername/www/www.yourwebsitename.dev/logs/error_log"
    CustomLog "/Users/yourusername/www/www.yourwebsitename.dev/logs/combined.log" common

In the above, just follow the same pattern I’ve shown for this example site. Don’t vary from this unless you want to do some research and testing. You can see I place a “public” folder insite the top directory for a particular virtual site – put your web documents to serve here.

hosts file

Edit your /etc/hosts file to add “www.yourwebsitename.dev” (your version of this) to a line starting with “” like this:     www.yourwebsitename.dev

Restart Apache

Using the XAMPP control stop and re-start Apache.


Komodo IDE macro to process current file with PHP Beautifier

I use Komodo IDE for dynamic languages. I like it because it works extremely well and you get a license to use it on whatever machine you happen to be sitting at. Also it works well in Ubuntu and Mac OS/X, both of which I use constantly.

Here’s a macro I use in Komodo to make the file I am currently editing instantly pretty:

var ke = komodo.editor
if (komodo.view.scintilla) { komodo.view.scintilla.focus(); }
var currentPos = komodo.editor.currentPos;
try {
    var tidycmd = "/usr/bin/php_beautifier -t1 -l 'Pear() ArrayNested IndentStyles() NewLines'"
    Run_RunEncodedCommand(window, tidycmd + " {'insertOutput': True, 'operateOnSelection': True}");
} catch (e) {
} finally {