I upgraded from Tiger to Leopard this week and wanted to provide a writeup covering everything you’ll need to know get to a good development environment ready on a fresh (clean) Leopard installation.
NOTE: Due to the subject matter contained in this post I am not providing any support for the following steps. Please make sure you’re comfortable with working with textfiles, etc. prior to beginning this process!
A few things you’ll need before we begin
- A good editor that you’re comfortable with (I use textmate)
- MySQL 5.0.45 binary (http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg)
- A MySQL GUI (I use CocoaMySQL)
- The latest version of cakePHP 1.2 (http://www.cakephp.org)
Let’s Begin
Apple bundles Leopard with PHP 5.2.4 & Apache 2.2.6. MySQL is not included by Apple.
MySQL does not have a fully compatible dmg package distribution for Leopard as of January 23rd 2008. So we’ll have to install a version meant for 10.4 and make it work.
Preparing the Console
Open terminal which is located in: …/Applications/Utilities/Terminal
Type the following (note mate is used because I have textmate, but vi or another editor will work as well)
sudo mate ~/.bash_login
If you already have text in this file you’ll be adding to it, if not, we’ll start from scratch. Here is what the file should look like:
export PATH="/usr/local/bin:/user/local/sbin:/usr/local/mysql/bin:/users/YOURUSER/sites/cake_1.2/cake/console:$PATH"
IMPORTANT!!! Make sure that /usr/local/bin and /usr/local/sbin are ALWAYS first in this file!
Save and close the .bash_login file.
From your home directory type:
sudo . ~/.bash_login
You should see nothing. If yo get an error, you’ve done something wrong.
Now that we’ve told the system where the binaries are for the apps we’re about to install let’s enable PHP 5.2.4.
Apple does not enable PHP 5 by default.
In the console type:
sudo mate /etc/apache2/httpd.conf
Scroll down to where the line:
#LoadModule php5_module libexec/apache2/libphp5.soDelete the # to uncomment this line to enable php 5.
Next, you’ll need to enable virtual host configurations. Scroll down to the line:
#Include /private/etc/apache2/extra/httpd-vhosts.confDelete the # to uncomment this line to enable virtual hosts.
Now, save and close the file.
Let’s install MySQL
Double-click on the MySQL installer we downloaded at the start of the tutorial. Install the application in the following order:
- MySQL
- Startup Item
- Pref Pane
This is only half of the story. You’ll notice that you cannot start MySQL from the preference pane.
Open your Terminal window and type:
sudo mysqlThis should start mysql. If it does not, please review the previous steps and make sure you’ve got the correct version of the MySQL installer.
The next thing we need to do is set the root password for MySQL. Type the following:
sudo mysqladmin -u root password "mynewpassword"
Now let’s test it out in CocoaMySQL. Install CocoaMySQL by double-clicking on the installer we downloaded earlier.
Open CocoaMySQL and use the following settings:
- host: localhost
- user: root
- password: the password you set
You should connect to the database.
While you’re in the database create:
- A user called cake and make the domain localhost
- A database called caketest
Let’s install cakePHP
Untar the cakePHP distribution we downloaded earlier and rename it to: cake_1.2
Move the whole directory to your user home/Sites/ It should look something like:
/Users/yourname/Sites/cake_1.2/
Notice that this matches the root of what we added into the bash_profile earlier. You can test the installation by going to your console and typing:
cd ~ cd Sites mkdir caketest cd caketest cake bake
You should see the cake bake prompt load and ask you if you’d like to create a new application from the default skeleton. You’ll answer y to this question.
I usually view the installation in verbose mode so answer y to the next question as well.
Once this has completed open the System Preferences panel.
Click on Sharing
Check the Web Sharing checkbox
Now you can visit your site at: http://192.168.1.100/~/caketest
You’ll notice that you don’t have a database.php yet and the page is all unstyled text instead of the nicely styled version you may have seen elsewhere.
Let’s address that by creating a virtual host.
Creating a Virtual Host
Open the System Preferences again and stop the Web Sharing by unchecking it.
Open Terminal and type the following:
sudo mate /private/etc/apache2/extra/httpd-vhosts.conf
Comment out everything.
Add the following:
DocumentRoot "/Users//Sites/caketest" ServerName caketest.dev ServerAlias www.caketest.dev Options FollowSymLinks AllowOverride All
Save the file and close it. This just set up a site we can access at: http://www.caketest.dev/
However, we need to do one more thing first! Open Terminal and type the following:
sudo mate /etc/hosts
Your file should look like this:
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 127.0.0.1 www.caketest.dev 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost
Notice that we added www.caketest.dev 127.0.0.1 after localhost. This tells the computer that whenever we type in www.caketest.dev take us to the virtualhost that we configured by the same ServerName.
Open System Preferences and enable Web Sharing again.
Open your browser and try typing: http://www.caketest.dev and you should see a styled version of what you saw before.
Let’s make sure cakePHP is talking to our database.
Open /caketest/config/database.php.default
Rename this file to: database.php
It should look like this after filling in the appropriate connection information:
var $default = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', 'port' => '', 'login' => 'cake', 'password' => 'cake', 'database' => 'caketest', 'schema' => '', 'prefix' => '', 'encoding' => '' );
Notice that we just replicated the information here that we used when we set up the database in CocoaMySQL.
Save the file and close it.
Now refresh your browser or visit: http://www.caketest.dev and you should see 4 messages:
- Your tmp directory is writable.
- The FileEngine is being used for caching. To change the config edit APP/config/core.php
- Your database configuration file is present.
- Cake is able to connect to the database.
Congratulations! You have just set up PHP 5 and MySQL 5 with CakePHP on your system and confirmed that everything is working.



August 15th, 2008
Just a quick note here to say that if you’ve commented out the lines in your httpd.conf file that directs Apache to look at the httpd-vhosts.conf then you will have to go in and edit your hosts file directly. Both methods will work. Thank you to GiveGoodWeb for pointing that out!
September 8th, 2008
Keith,
Do you know anything about installing cake onto Windows XP Pro?
I tried to leave a comment where your comment lives about your tutorial but for some reason it asks for my userid and password again even though I am logged into the Bakery (why?) and then, when I reenter this information, it hangs up. I am completely new to cake but am getting frustrated with the site and the whole enterprise very quickly.
I have been trying to effect a simple install of cake for three weeks now…still getting nowhere. I have apache2 rup and running OK but have no clue how to configure apache2 to run cake.
Jerry Ross
September 9th, 2008
Hi Jerry,
For Windows XP Pro you’ll need Apache2 up and running which it looks like you’ve done. Then you’ll want to install PHP (www.php.net) and after that you can do the installation of cakePHP (www.cakephp.org). Hope that helps and I may write up a quick tutorial on getting cakePHP up and running on Windows in the future.
EDIT: I actually went ahead and added a new post to help you out Jerry. Hope the tutorial works out for you and anyone else who needs it!
December 28th, 2008
Thanks for this great tutorial.
Even tho after editing httpd.conf to enable vhosts Web Sharing won’t work (Mac OS X 10.5.6), by letting the vhosts option commented I got it working!
I came from Windows world into Mac and still have some problems as a developer, still thinking which OS to addopt but wich people like you that share their knowledge this will make it a less harder for us.
Thanks again,
Cristian