Getting Started With CakePHP

Here’s a couple of things I did wrong when trying to use CakePHP, for your benefit.

Several months ago I applied at a company called Radar Hill, which uses Cake as their main framework. Naturally I set about learning how to use it as soon as possible. I didn’t do very well. I it on Rocketships, but couldn’t figure out how to make it run – there were a variety of problems that I’m not quite experienced enough to recognize.

Then I tried it locally on my MacBook. I made progress, but the database part stumped me until I found out about MAMP, which got me a little further. But it still wasn’t what you’d call a success. Finally, the job interview at Radar Hill rolled around, and I was not hired, mainly because of my inexperience with PHP. Sigh. I tried!

However, the guys who interviewed me were very encouraging, and said to keep trying and stay in touch. One, Jamie, gave me some tips on how to run it on the Mac. His instructions worked perfectly.

First Mistake

.htaccess files sometimes don’t copy and paste in the Mac finder, because the . at the beginning of the file name renders them invisible (except when it doesn’t).

Probably the hardest to do but uses the least amount of work and has the most potential to go wrong, that is the Terminal Method. If you open up terminal (Applications > Utilities) and type the following:

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

This will show you all of the hidden files and folders on your operating system. If you want to reverse the command replace TRUE with FALSE.

Then check the Cake files to make sure that all 3 .htaccess files are present – as detailed by this very helpful post on Stack Overflow. There should be one at the top level of your cake directory, one in /app, and one in /app/webroot.

Second Mistake

I was putting files in all sort of random places, trying to find a way that worked. Jamie said to unzip the Cake download into /MAMP/htdocs, replacing anything else in that directory. This is probably a dumb newb mistake, but I’m sure at least one other person has made it.

What Jamie Said

#1: Download and install MAMP:

1

<a>http://www.mamp.info/en/index.<wbr />html</a>

It’s an “out-of-the-box” LAMP environment for the Mac. It’s all I ever use.

#2: Start MAMP, and then go to the homepage, which by default is:

1

<a>http://localhost:8888/MAMP/?<wbr />language=English</a>

#3: Click on the “phpMyAdmin” tab at the top. You can also get there
directly:

1

<a>http://localhost:8888/<wbr />phpMyAdmin/</a>

Create a new database and call it whatever you want – something descriptive.

#4: Download the latest version of CakePHP 2.2, currently RC1, from here:

1

<a>https://github.com/cakephp/<wbr />cakephp/tags</a>

#5: Extract the archive and put its contents into
/Applications/MAMP/htdocs (replace whatever’s there).

Open the database config file for editing, which is at (relative to htdocs):

app/Config/database.php.default

#6: In the DATABASE_CONFIG class in the file you’ll see this array,
which is the default DB config:

1

2

3

4

5

6

7

8

9

10

public$default=array(

'datasource'=&gt;'Database/Mysql',

'persistent'=&gt;false,

'host'=&gt;'localhost',

'login'=&gt;'user',

'password'=&gt;'password',

'database'=&gt;'database_name',

'prefix'=&gt;'',

//'encoding' =&gt; 'utf8',

);

Change it to this:

1

2

3

4

5

6

7

8

9

10

public$default=array(

'datasource'=&gt;'Database/Mysql',

'persistent'=&gt;false,

'host'=&gt;'localhost',

'login'=&gt;'root',

'password'=&gt;'root',

'database'=&gt;'your_database_name',

'prefix'=&gt;'',

'port'=&gt;8889

);

#7: IMPORTANTLY: don’t forget to replace “your_database_name” above with
the actual name of the DB that you created.