Easy CakePHP in Ubuntu

I’ve always setup a new CakePHP project by extracting the current stable build into a project directory and editing the core.php and database.php files manually. I usually then change to the /cake/console directory of the project and run php cake.php bake (having already installed the php-cli) to bake my code.

I know there are other ways to make this process simpler but its always just worked for me and I am usually to lazy/busy/unmotivated to try something new.

Today, however, I stumbled across a great way to set up CakePHP in Ubuntu so that building new projects is a simple matter of running one line from the command line and you are ensured of using the same stable “shell” version of Cake each time. It is also extremely easy to upgrade your “shell” version whenever you want. (It also makes baking even easier than the way I was doing it but that’s just an added bonus !)

(This may or may not also be possible in other Ubuntu like systems that have the same CakePHP repositories eg Mint, Debian etc)

1) Download and extract the latest stable version of CakePHP to a folder on your machine.

2) Install cakephp-scripts from the Ubuntu repositories

$ sudo apt-get install cakephp-scripts

This will install the current version of CakePHP in the Ubuntu repository, as well as the php-cli (command line interface) and setup the Cake console for easy use from the command line.

3) Copy the folders from the latest stable version to your system

Currently you have installed whatever version of cake was included in your version of Ubuntu’s repositories. If you are running an older version of Ubuntu or just want to run the very latest stable version, you need to update your Cake version by copying it from the extracted folder in step 1.

The “shell” version of CakePHP you installed in step 2 is located in /usr/share/php/cake. You will notice that the directory structure is slightly different from the extracted version, but a little common sense will enable you to see what needs to be copied to where (basically, from the extracted directory, copy the app directory and everything from inside the cake directory into the /usr/share/php/cake directory).

You can also upgrade your “shell” by downloading/extracting a newer stable version of CakePHP and repeating the above step.

Now baking with Cake becomes even easier.

Change to your web root (usually /var/www/ or wherever you usually develop your PHP applications) and run

$ cake bake projectname

where projectname is the name of a new project you want to create. You will be presented with the Cake console, which will set up your project folder and copy over all the code from the CakePHP “shell”. It will also set up a random Security Salt value, add some default CAKE_CORE_INCLUDE_PATHs and guide you through setting up your database configuration(s).

You can then change directory to your projectname directory and run

$ cake bake

to bake your Models, Views and Controllers.

Happy Baking…

UPDATE: I just noticed another nice side effect of this way of creating Cake projects, default app_controller.php, app_helper.php and app_model.php files are created in the project root folder. 😉


Posted

in

by

Tags:

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.