Context

The CakePHP community has just recently begun actively pushing out version 1.3-beta (download here) of the framework. It is of course still in beta and version 1.2.5 is considered the stable release, however I've been hearing mostly success stories from people making the upgrade, such as Miles Johnson's "flawless upgrade" post.

Today, it just so happens, I had an idea for a new webapp so as I began undertaking some RAD I thought it would be a good chance to test out the newest release, particularly considering the new features sparked my interest (such as virtual fields). Not long in though I hit a brick wall - my command line "cake" command is for CakePHP 1.2x. Easy fix if I switched everything to 1.3x, except I wasn't ready for that leap and it was turning RAD into SAD (Slow Application Development). Thus the task of figuring out how to run them side by side presented itself.

To the point

Running multiple CakePHP releases on one machine ended up being easy enough, however it took a few different approaches to reach the final solution written up here.

These instructions are for a Mac OSX environment - they might work on Linux, however for Windows users I don't have a solution (if you have one though please let me know in the comments or via email).

UPDATE: Tony Milne has provided a solution for Windows in his comment below.

Step 1: Setup directory structure

I have placed CakePHP 1.2x and CakePHP 1.3x in folders /usr/local/cake2 and /usr/local/cake3 respectively. You can install these directories wherever you like, just modify any paths from now on accordingly. Also when adding them ensure the "cake" folder is intact within each of the folders (you'll get nasty errors otherwise).


/usr
	/local
		/cake2
			/cake
				...
		/cake3
			/cake
				...

Step 2: Edit ~/.profile (or ~/.bash_profile)

You'll most likely already have a ~/.profile file with PATH variable declared inside (sometimes its in ~/.bash_profile). If you've already mapped a CakePHP release in your PATH variable, remove it - which will prevent cake being used on the command line, but we'll wire things up later.

After that add the code show below:


# Aliases
ALIAS=$HOME/.alias
export ALIAS
. $ALIAS

Save and close.

Step 3: Edit/Create ~/.alias

Open the file ~/.alias or create it if it doesn't exist. Then insert the following lines:


# begin .alias
alias cake2="/usr/local/cake2/cake/console/cake"
alias cake3="/usr/local/cake3/cake/console/cake"

Save and close.

Step 4: Reload ~/.profile

Run this command to reload the settings in ~/.profile :


. .profile

Step 5: Test it out

That's all there is to it. Test it out by using either cake2 or cake3 in the command line.

Extras

Just a few small extras (just for fun) while you're editing these files.

If you haven't already added colours to your command prompt, throw this in your ~/.profile file aswell - makes the Terminal that little bit nicer.


export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

You can also add more command line shortcuts (such as the following) to your ~/.alias file.


alias del="rm -i"
alias dir="ls -al"
alias search="grep"