A Simple Start: Running Cake on a
Localhost Environment
Before you begin running Cake, you will need the following already working on your localhost
(see Appendix A for more details about installing these components):
• Apache server with mod_rewrite
• PHP 4.3.2 or greater
• MySQL (Cake does support PostgreSQL, Microsoft SQL Server 2000, Firebird, IBM DB2,
Oracle, SQLite, ODBC, and ADOdb, but I’ll stick with MySQL in this book because it’s
the default database engine in Cake)
Running the Setup Routines
Every time you install a Cake application on your localhost, you’ll follow these routine
procedures:
1. Prepare the tmp folder.
2. Change the Security.salt value in app/config/core.php.
3. Enter MySQL database connection settings.
4. Design your database schema (unless you are using an existing schema).
Preparing the tmp Folder for Cake to Read and Write Temp Files
The tmp folder is located in the app folder. By default, its permissions are set to 0777, but it is
possible for it to change to a server permissions default. The Cake welcome screen tells you
whether the tmp folder is writable. If this bar lights up green, then the tmp folder doesn’t need
to be adjusted. If not, run the following at the command line to change the tmp permissions
and its enclosures:
chmod -R 0777 tmp
Changing the Security.salt Value
When a session is initialized, the server groups a set of requests together using a session ID, a
database, or a cookie. Whatever the method, the idea behind the session is that the server can
maintain a pseudoconnection with the user, even though the communication could get interrupted
along the way. You’ve run into this when you’ve logged into your web-based e-mail
account or some similar web service. The site application knows that you’re logged in and
maintains that status until you log out or a certain length of inactivity transpires.
Luckily, Cake makes session handling easy. But you need to make sure that its session
string is secure. You wouldn’t want any users to toy with the session handling in an effort to
break into your applications.
To add some security to the session variables, open the app/config/core.php file, and
locate line 153, or thereabouts. You’ll find a line that looks like this:
Configure::write(‘Security.salt’, ‘DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi’);
Entering MySQL Connection Settings
Cake needs to know where your databases are located to save and retrieve data. You do this
by editing the app/config/database.php.default file. You’ll need to rename the file to
database.php (remove the .default from the end) and edit it in the plain-text editor of your
choice. However your localhost is set up, you will need to know the MySQL login and password
for Cake to connect to the database. This is generally set to a default value unless you
configure the administrator’s account (for example, the login and password have default
values of root and so forth). In the database configuration, there will be a place for you to
enter the login and password values. Listing 2-1 shows the default DATABASE_CONFIG class in
the database configuration file.
Listing 2-1. The Database Configuration File
1 class DATABASE_CONFIG {
2
3 var $default = array(
4 ‘driver’ => ‘mysql’,
5 ‘persistent’ => false,
6 ‘host’ => ‘localhost’,
7 ‘port’=>”,
8 ‘login’ => ‘user’,
9 ‘password’ => ‘password’,
10 ‘database’ => ‘project_name’,
11 ‘schema’=>”,
12 ‘prefix’ => ”,
13 ‘encoding’=>”
14 );
15
16 var $test = array(
17 ‘driver’ => ‘mysql’,
18 ‘persistent’ => false,
19 ‘host’ => ‘localhost’,
20 ‘port’=>”,
21 ‘login’ => ‘user’,
22 ‘password’ => ‘password’,
23 ‘database’ => ‘project_name-test’,
24 ‘schema’=>”,
25 ‘prefix’ => ”
26 ‘encoding’=>”
27 );
28 }
In this class DATABASE_CONFIG, there are two databases it will connect with: default and
test. If you have no intention of creating a separate test database, you can delete lines 13–21.
Plop your database settings into the necessary lines, as shown in Listing 2-2.
Listing 2-2. Adding the Localhost Settings to Your Database Configuration
3 var $default = array(
4 ‘driver’ => ‘mysql’,
5 ‘persistent’ => false,
6 ‘host’ => ‘localhost’,
7 ‘port’=>”,
8 ‘login’ => ‘root’,
9 ‘password’ => ‘root’,
10 ‘database’ => ‘cake’,
11 ‘schema’=>”,
12 ‘prefix’ => ”,
13 ‘encoding’=>”
14 );