So here I am, trying my darnedest to find the time to learn Rails, but it seems that the world just wants me to continue to do the PHP thing. Fine. If I must, I must. So who wants a slice of Cake?
From what I’ve read, and seen, CakePHP is almost the equivalent of Rails on the PHP side. Almost. Anyway, my theory is that what I learn from Cake I might be able to take to Rails. Maybe. It’s all MVC… right? But anyway, the following is what I’ve learned in my attempts to get a Cake development environment up and running on the Mac (because there seems to be a severe lack of tutorialage for this on the internets). And yes, in the end, I triumphed. Mostly. And so will you. Hopefully.
First, you need to know that I’m using Mac OS X Snow Leopard (10.6.2). And as far as a local PHP server setup is concerned, nothing is easier than MAMP… one click install and you’ve got PHP and MySQL running like a champ. So here’s what you need to do to get Cake up and running on this rig (specifically the database configuration and bake… which is where I ran into trouble):
- Download and install MAMP. Launch it. You should see the MAMP startup page in your browser. Nothing more needs to be said about this.
- Download Cake (version 1.2.5 as of this writing).
- Unzip it and put it… wherever you want, really. I’d recommend putting it in your MAMP folder (which lives in your Applications folder). Also you might want to rename the folder to something a little easier to work with, like “cake” (don’t get me wrong, “cakephp-cakephp1x-5dd6e55″ is a great name for a folder. Really, it is. It’s just not quite what I’m looking for).
- Now let’s bake a new app (this is where my troubles began. But you get to benefit from my misery, you lucky dog). Open terminal and cd to MAMP’s web root (the htdocs folder)… like this (obviously change “sam” to your computer/user’s name):
sam:~ sam$ cd /Applications/MAMP/htdocs
Hint: you can just type “cd ” and then open a finder window, navigate to the folder, and drag it to your terminal window. The path to the folder will appear! Less typing = good. - Get to the cake console (it’s buried within that folder from step 2) and run the bake command (again, drag the file from finder into the terminal window so you don’t have type all this):
sam:htdocs sam$ /Applications/MAMP/cake/cake/console/cake bake newapp
Note: if you put your cake folder elsewhere, your path will be different.
Note 2: “newapp” is the name of the new app that I’m baking with this command. You can call your app whatever you want. As far as I can tell, this just affects the folder name that the app will be put in.
Note 3: there’s something about setting the environment variables so you don’t have to type the whole path to the Cake console every time you run the Cake console. I couldn’t figure out how to do this. I followed a lot of tutorials and tips out there, but to no avail. Maybe something has changed in Snow Leopard? If you know how to do this, let me know in the comments! - If all has gone well so far, you be left at a prompt asking you if everything looks okay. Hit return (this will automatically insert the default response (in this case, “y”) and advance you to the next question).
- You’ll continue to use the default answers (just keep hitting Return) until you get to the Port prompt in the Database Configuration section. Enter this:
'/Applications/MAMP/tmp/mysql/mysql.sock'
You can use MAMP’s default mysql port (8889) but you’ll get into trouble later on when you try to bake a controller. So just use this path. Really. Do it. Don’t ask why. Because I don’t know (actually, if anyone knows why, please enlighten us in the comments). - Keep going and use the defaults until you get to the Password prompt. Unless you’ve changed something in MAMP, you’ll be using the very secure password of “root”.
- For Database Name, I’d suggest calling your database by the same name of your app. So in my case, it’d be “newapp”.
- Continue with the defaults until you’re through.
- Now let’s create your database. Go to your browser to see the default MAMP startup page. If it’s not there (because you got distracted by a particularly amusing LOL cat link (it’s okay. It happens to all of us)), go back to the MAMP app and click the button “Open start page”. It’ll load this URL:
http://localhost:8888/MAMP/?language=English - Click the phpMyAdmin tab at the top of the page and marvel at the sheer ugliness of phpMyAdmin. It gets the job done though. (For something prettier and just as free, I’d recommend Sequel Pro.)
- Right there on the front page is a section that allows you to create a new database. Conveniently, it’s called “Create a new database”. Enter the name of your database (from step 9) and hit create.
- Cross you fingers as you head over to your app’s root directory in your browser:
http://localhost:8888/newapp/
Again, replace “newapp” with whatever you named your app. - You should see four green bars indicating that your new app is successfully configured.
- Now go get yourself a beer. You deserve it.
So at this point you should be able to use the bake command to bake all sorts of controllers and models and other things that I’m forgetting about. Just enter
/Applications/MAMP/cake/cake/console/cake bake _____
in terminal (really though… you shouldn’t have to enter that whole thing. You should be able to just type “cake bake _____” at the command prompt. Man, that’s frustrating. Environment variables? Path? Snow Leopard? What? Where? Anyone? Hello?).