As part of my experiment with the Twitter API, I decided to use CakePHP as the framework because of its “rapid deployment” strategy. While there are many frameworks out there to choose from, I liked this one because it follows the MVC (Model View Controller) pattern like Ruby on Rails (another side project of mine). The following will summarize the remarkably easy install, based on Media Temple’s popular Gridserver package since that’s what I’ll be using for this project.
Before we begin, let’s cover the basics. To follow these instructions, you are going to need:
- An FTP client. On a Mac, I recommend Transmit. On a PC, you are on your own
- Some sort of text editor. Many FTP clients come with text editors, but I use Textmate. You can also use basic apps like Textmate or Notepad, but be wary of any program that when saved can add bloat or won’t be UTF-8 compatible, like WordPad, TextEdit, or (heaven forbid) MS Word
- Knowledge of how to create MySQL databases.
- A Media Temple Gridserver account. This is a no-brainer considering that you are reading this post, but should you happen to not have one, feel free to mention elihorne.com in the registration process!
To start, you should create two MySQL databases via the Media Temple Account Center. You can refer to the Knowledge Base for instructions on how to do this. I made “cake” and “cake_test”. Keep this page open, because we will need it later.
Now, Download the latest version of the CakePHP framework (at the time of this writing, stable version 1.1.19.6305. I do not recommend downloading beta unless you really know what you are doing). Unpack, unzip, and keep the file location handy. I tend to keep files that I’m downloading and subsequently deleting on the desktop, but that is a matter of personal preference.
Next, fire up your FTP client, and log into your (mt) account. While the primary domain and password depend on your settings, don’t forget that the username is “serveradmin@your-primary-domain.com”. Once logged in, you should see a list of directories that looks something like
- containers
- data
- domains
- etc
- logs
- stats
- users
You want to drill down into (open) “domains,” where you should see at the very least the domain where you want to install Cake, as well as any other domains you might have attached to the account.
Inside of this directory, upload the “cake” folder as well as the “vendors” folder. Once that has completed, upload the contents of app into the domain folder you’ve selected. This is to say, if you were to open your “domain.com folder”, you would see the pre-existing html and cgi-bin along with your new directories
- config
- controllers
- models
- plugins
- tmp
- vendors
- views
- webroot
Once that whole upload is done, backup any content you have inside the “html” directory, and then delete it. Now rename the “webroot” folder to “html“.
Guess what, you are almost there! Stick with it.
Now all the uploading is done. Let’s start modifying some files. Inside the newly renamed html folder you will find amongst other things a file called “index.php”. At the top of the document, but after the opening “<?php” statement, paste in the following:
define('ROOT', '/home/YOUR-SERVER-NUMBER/domains');
define('WEBROOT_DIR', '/home/YOUR-SERVER-NUMBER/domains/YOUR-DOMAIN.com/html');
define('APP_DIR', 'YOUR-DOMAIN.com');
define('APP_PATH', '/home/YOUR-SERVER-NUMBER/domains/YOUR-DOMAIN.com/');
define('CAKE_CORE_INCLUDE_PATH', '/home/YOUR-SERVER-NUMBER/domains/cake');
define('CORE_PATH', '/home/YOUR-SERVER-NUMBER/domains/');
You will want to replace “YOUR-SERVER-NUMBER” with the number associated with your Media Temple account. If you don’t know this, drill back out of the current directory until you get back to “domains.” Inside of there you will see an alias that looks like “s#####.gridserver.com”. The 5 numbers after the “s” is your server number. Replace “YOUR-DOMAIN” with the domain you want to install Cake on. Obviously it doesn’t have to be a .com, but I put that in there for reference. Feel free to insert your appropriate info.
Finally, we need to hook up the database information. If you had to navigate back to find your server number, go back to where you were before. Now, look for a “config” directory. Inside of there you will find a file called “database.php.default”. Open in. Inside, towards the bottom, you will find all the configuration information to get Cake talking to the databases we made at the beginning. The only things you need to modify on this page are:
- host
- login
- password
- database
Back on that ac.mediatemple.net database configuration page we left open, copy over that info. Your “host” info will be something like internal-db.s#####.gridserver.com (again, the pound symbols are your personal server numbers). You can get the site-wide login and password info from that same page (hit “show” if you don’t remember it). Save, close. Rename it “database.php“.
Ok. We are done! Not too bad, right?
Now it is time to check to make sure everything worked. Fire open your favorite browser, and visit your domain.com. If everything went well, you should see a welcome page from the Cake team saying that your database config file is present, and that cake can connect to the database (looks like this). If not, go back to step one and make sure that you followed all the steps correctly.
Enjoy!
















As I mentioned over Twitter, I don’t think that heavy OO MVC frameworks are a good fit for PHP. Rails works very well in Ruby because it takes advantage of how Ruby makes it easy to write very pretty APIs in an OO manner in addition to declarative DSLs.
In contrast, PHP had OOP bolted on later in its life, presumably to appease Java droids who get nervous when they look at a toolbox that doesn’t look like the one they used in school.
PHP, as a syntax, isn’t great. (It just stole some ideas from Perl but made it a bit less expressive.)
What makes it a good choice for many web projects is that it has so many variables and functions already set for you. The language gives you a lightweight framework for free.
Each page is a controller. At the top, require the models you need for that page and a nice big utils.php that supplements the builtin functions. At the end, use Smarty or call a PHP Template to do your View.
If you want prettier URLs, mod_rewrite is there.
I imagine my view is an uncommon and possibly unpopular one, but I think PHP really shines for simple declarative code. It seems silly to try to shoehorn it into looking like an ugly step sister of Ruby (or Java, for that matter).
aahh chaz, you give me a reason to check my comments.
First let me say: java droids and shoe horned ugly step sisters made my friday.
Secondly, while I’m in no position to comment on Cake at this point in time, I do like the similarity (even if it is imitation) that this has to what little I’ve done with RoR.
I’m assuming that I’ll still be toiling with this by next weekend, where it will either go live, or die with a whimper and serve as a learning experience. Either way, I reserve my right to comment then!
thanks for this! did you have any trouble with getting the mod_rewrites to work on mediatemple? where do you put the .htaccess file(s) and what do they look like?
for some reason, i have to do a force redirect to get the pages to show up — if i don’t i end up seeing the default home page for all urls. this is what my .htaccess looks like:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [R,L,QSA]
I did not have any issues getting mod_rewrites to work, although I must admit I didn’t fiddle with them too much.
I put the .htaccess file in the webroot (/html), and pretty much left the configuration the same as it arrived in the download.
Mine looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Hey, just a quick ‘thanks’. These instructions worked a treat.
@ben glad somebody benefited from this!