How to Install CakePHP on a Mac
So you wanna join the web frameworks bandwagon, but you don’t want to have to learn Ruby? CakePHP is probably your best bet. In this tutorial, I’m going to give step by step instructions for getting this to work on a Mac. If you’re a PC user, it’ll all still probably work fine, I just haven’t tested this method in that environment yet.
Get a Localhost Set Up
If you’re new to web development, you ought to know that there are two ways of testing your software: 1, code everything and upload it, then browse to the site and test the link; or 2, set up a localhost on your machine and run it from there. Don’t even think about doing it the first way! That will take you forever. Here’s how to set up a localhost on your Mac easily.
First, go to Apache Friends. Download the installation files and run them. You’ll end up with a folder in your Applications folder called “xampp.” Next, download the following helper files: Mampp Auto Start/Stop. Place these in your folder titled “xampp” and launch the file “mamppstart.” (You can, if you want, open either of these files using the AppleScript script editor program to save your password. Then, when you launch these, xampp will automatically start without you having to type in your root password.)
Now, if you open your web browser, when you type “http://localhost” you should get a welcome screen for xampp.

In your xampp folder, there’s another folder called “htdocs.” Whatever you place in this folder is then accessible via the localhost. For example, if I create a folder called “dave” in the htdocs directory, and place an index.html file in that folder, then when I browse to “http://localhost/dave” that file will be brought into the browser.
Now that we can run PHP files on the localhost, let’s install Cake!
Installing CakePHP
Go to the CakePHP website and download the latest release of CakePHP. (On their site they have a large link to the left that you can’t miss called “Download it Now!”.) Extract either the .bz2, .tar, or .zip file to get a folder called “cake_x.x.x.xxxx” (At the time of this post, I got the folder “cake_1.1.8.3544.” You can rename the folder to anything you want, say “testdrive,” and then place it into the xampp/htdocs directory. Now when you type http://localhost/testdrive, you should get a screen like this:

To get it working right, we need to set up some databases and get those databases linked up to Cake. To do this the easy way, we need to install some helper apps.
Getting MySQL installed
Xampp comes with MySQL. If you like, you can just go to http://localhost while xampp is running, and launch PHPMyAdmin to access your databases. But, if you’re like me, using a mouse can be cumbersome, and I like a nifty little program called CocoaMySQL. Download and install this program and you’ll end up with this handy screen when you launch it:

Type in the following info to access MySQL:
Host: localhost
User: root
Password: [your password]
Socket: /Applications/xampp/xamppfiles/var/mysql/mysql.sock
Now you’re in business. Create a new database, called “testdrive” and a new table called “records.” Next we just have to link up this database with CakePHP.
Configuring MySQL with Cake
In your testdrive folder, there’s another folder called app. Open config and rename the file database.php.default to just database.php. Now, open database.php and add your information to link it to the database. (In our example, the following will link up Cake with MySQL.)
Connect: mysql_connect
Host: localhost
Login: root
Password: [password]
Database: testdrive
Prefix: [left empty].
You’ll notice that there are two arrays listed there, $default and $test. I like to just put the same in both, to make it easy on myself (in other words, use just one database for both test and default environments). Now, go back to http://localhost/testdrive and you should see a notice that says “Cake is able to connect to the database.” Cake is now fully configured and running with your database!
A Simple Program Using the Cake Framework
Now that we’ve got Cake running with xampp and MySQL, let’s get a program going. Go to the app folder and create a new file in the controllers folder called records_controller.php. We’ve called it “records” because that corresponds with the table name we created earlier. With the “_controller.php” following, Cake will be able to link up this controller file with the table in our database and run some functions for us.
In the records_controller.php file, paste the following lines:
<?
class RecordsController extends AppController {
var $name = "Records";
var $scaffold;
}
?>
This tells Cake to run a scaffold of the database. But, we still need to create a model file that will do the talking to the database and supply data. Because we’re using a scaffold, we won’t need to do anything more than identify the name of the table. Create a new file called record.php and place it in the app/models folder. Paste the following lines in this file:
<?
class Record extends AppModel {
var $name = "Record";
}
?>
Browse to http://localhost/testdrive/records and you’ll get the scaffold view of the database. Notice that there are lots of error notices that are at the top. These resulted from file permissions not being set correctly. We do that now by opening the Terminal and typing the following lines:
#: sudo su
#: cd /Applications/xampp/htdocs/testdrive/app
#: chmod -R 777 tmp
Now that the permissions are set correctly, you should see this:

Let’s say you want a simple database program that will list email addresses for you with the name of the person. On the fly, all you have to do is go into CocoaMySQL and add the necessary fields. I did the following:
name [varchar] [255]
email [varchar] [255]
Go back to http://localhost/testdrive/records and voila! Cake has already caught the changes and is working with them. You can click on New to create a new record, and all is figured out. As you can see, working within a framework can shave off a lot of time, especially for simple database calls that normally you’d have to do with mysql_query("SELECT * from ... "); strings. The scaffolding does all this for you.
I recommend using some of the walkthroughs on the Cake site. They have a good manual and wiki to help you through it all. And if you’re having tons of problems, go ahead and drop me a line.
Comments
David Golding Design | | Web and Print Solutions
Oct 25th, 2006, 4:53 pm
[...] For a detailed step-by-step installation of both Xampp and MySQL, see my other article, How to Install CakePHP on a Mac. It’s the same for PCs too. [...]

How to Install CakePHP on a Mac at There was Code; Then there was AJAX!
Oct 19th, 2006, 12:28 am
[...] CakePHP is like Ruby on Rails for PHP. This story shows how to install it on a Mac the easy way without any serious technical stuff.read more | digg story Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages. [...]