Managing Multiple Versions of CakePHP on Linux

If you're developing several different applications with CakePHP, over time it's easy to run into issues with running different versions of CakePHP across your applications. After a while it may become difficult to keep everything properly organized. Your directory structure can end up looking something like this:

cake_1.1.x/
app1/
cake/
cake_1.2.alpha/
app2/
cake/
cake_1.2.prebeta/
app3/
cake/

This works, but I greatly dislike having all of my applications spread across a file system, and each in a different place depending on what version I'm running. If I want to upgrade to a new version, I have to actually move directories around. That's no good at all.
You could go in and muck about with your app/webroot/index.php file and change the paths to the cake install, but that just means now instead of moving directories you're having to edit hard-coded paths. That's no good either.
What we'd like to see is something like this:

cake_distros/
cake_1.1.x/
cake/
cake_1.2.alpha/
cake/
cake_1.2.prebeta/
cake/
apps/
www.app1.com/
app1/
controllers/
webroot/
www.app2.com/
app2/
controllers/
webroot/
www.app3.com/
app3/
controllers/
webroot/

(I'm leaving out some of the directories that should be included inthe cake app for the sake of brevity.)
How do we accomplish this without actually moving files around or editing hard-coded paths?
One way to do it on a *nix file system is to employ the use of symbolic links. In this case we want to indicate which version of CakePHP to use and where it's located in the filesystem.
To create a symbolic link, in the example above you would run:

$ ln -s cake_distros/cake_1.1.x/cake www.app1.com/cake
$ ln -s cake_distros/cake_1.2.alpha/cake www.app2.com/cake
$ ln -s cake_distros/cake_1.2.prebeta/cake www.app2.com/cake

The advantage of using symbolic links is that now we we have a cake install that still expects the usual setup (with 'app' and 'cake' in the same directory). To upgrade app1 from CakePHP 1.1 to 1.2 pre beta all we have to do is:

$ rm www.app1.com/cake
$ ln -s cake_distros/cake_1.2.prebeta/cake www.app1.com/cake

If you're working in a development environment, you can quickly move from one version to another by creating two symbolic links and moving them back and forth. Example:

# use cake 1.1
$ ln -s cake_distros/cake_1.1.x/cake www.app1.com/cake
# create sym link for 1.2
$ ln -s cake_distros/cake_1.1.prebeta/cake www.app1.com/cake_1.2
# use cake 1.2
$ mv www.app1.com/cake www.app1.com/cake_1.1
$ mv www.app1.com/cake_1.2 www.app1.com/cake
# go back to cake 1.1
$ mv www.app1.com/cake www.app1.com/cake_1.2
$ mv www.app1.com/cake_1.1 www.app1.com/cake

This, in my opinion, is far superior to moving around directories or mucking about with configuration files.
I hope this is helpful. If you think there are problems with this approach, feel free to let me know. Any questions? Just post them.