Before you can start with baking an application you have to do some preparations. Those preparations differ from developer to developer. So the following is just one possible way, my way, of doing those preparations. It is the way that works for me now, but of course it can and will change in the future as it has in the past. As this article is about preparations you have to do for each project I will omit things like the installation of CakePHP.

First a summary of the steps involved:

  • Create a repository for the project
  • Create a project in the IDE
  • Bake the application skeleton
  • Create a database
  • Rename database.php.default to database.php and modify it
  • Modify app/webroot/index.php
  • Make hosts entry
  • Create virtual host

Create a repository for the project
I strongly recommend to use a version control system like CVS or Subversion for each project, even if you are the only developer. To the creation of a project repository itself I cannot say much, because I use the web-based tool provided by my hoster.

Create a project in the IDE
In my IDE, PHPEclipse, I then check-out the empty project from the repository and create a PHP project. In this project I usually create two folders, “trunk” and “live”, and commit them to the repository. These folders will contain the development version resp. live version of the project.

Bake the application skeleton
After a switch to the command line I use the bake script to create the application skeleton for my project with:

dho@tumulux:~/projects/cake_1.2.x.x/cake/scripts$ php bake.php -project /home/dho/projects/projectxy/trunk/app

Create a database
As I am already on the command line I create the MySQL database for the project:

dho@tumulux:~$ mysql -u root
mysql> create database projectxy;
mysql> quit
dho@tumulux:~$

To make my life easier I use the root user without a password for all database-related activities on my development system (as you can guess it is a bad idea to use that approach on a live server *g*).

Rename database.php.default to database.php and modify it
To use the previously created database with CakePHP, two steps have to be performed. The first is to rename the file database.php.default in app/config to database.php. And the second step is to modify the database configuration:

var $default = array('driver' => 'mysql',
    'connect' => 'mysql_connect',
    'host' => 'localhost',
    'login' => 'root',
    'password' => '',
    'database' => 'projectxy',
    'prefix' => '');

Modify app/webroot/index.php
As I use an advanced setup, i.e. one cake installation and multiple applications, I have to change some constants in the file app/webroot/index.php:

define('ROOT', '/home/dho/projects/projectxy/trunk');
define('APP_DIR', 'app');
define('CAKE_CORE_INCLUDE_PATH', '/home/dho/projects/cake_1.2.x.x');

Make hosts entry
As I want to have the development environment as similar as the live environment, I add an entry to /etc/hosts for each project:

127.0.0.1      projectxy.localhost        localhost

Create virtual host
As I use a production setup for development purposes, I define a virtual host in /etc/apache2/sites-available/default that looks like:

<VirtualHost *>
    ServerName projectxy.localhost:80
    DocumentRoot /home/dho/projects/projectxy/trunk/app/webroot

    ErrorLog /var/log/apache2/projectxy_error.log
    CustomLog /var/log/apache2/projectxy_access.log combined
</VirtualHost>

After this change I have to restart the Apache web server with

dho@tumulux:~$ apache2 -k restart

Finish
And voilà, if I request http://projectxy.localhost with my browser I get the default cake page saying the database configuration file is present and that cake can connect to the database. With that I am ready to start baking my application :)