nerdbot.com yeah, the internet remembers things much more accurately than I ever could…
Categories: Tutorial

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):

  1. Download and install MAMP. Launch it. You should see the MAMP startup page in your browser. Nothing more needs to be said about this.
  2. Download Cake (version 1.2.5 as of this writing).
  3. 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).
  4. 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.
  5. 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!
  6. 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).
  7. 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).
  8. 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”.
  9. For Database Name, I’d suggest calling your database by the same name of your app. So in my case, it’d be “newapp”.
  10. Continue with the defaults until you’re through.
  11. 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
  12. 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.)
  13. 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.
  14. 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.
  15. You should see four green bars indicating that your new app is successfully configured.
  16. 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?).

Tags: , , ,
Categories: Macintoshery

Damn. I keep forgetting that the purpose of this blog isn’t to write profound pieces of prose (or astounding achievements in alliteration). Nope, ‘cuz that’s what killed the last blog… the pressure. This one is all about getting juicy morsels of tech/tips/code/hackery out into that ever expanding void known only as the internet. That way it’s findable. That way, dear reader, you don’t have to suffer as I did.

So having said that, here’s a juicy morsel, in handy tip format: Apparently, Mac OS X 10.5, Leopard changed the location of a crucial MySQL file. PHP can’t find it anymore. To be honest, I don’t know the extent of the damage this causes, but it definitely makes WordPress unhappy (WordPress won’t connect to MySQL. Yeah… that’s somewhat of a problem).  So here’s how you fix it:

  1. Crack open the WordPress config file that you’re going to need to crack open to config WordPress anyway. You know, wp-config-sample.php.
  2. Punch in the normal config info… database name, username, password…
  3. After that, there’s a line that asks for the DB-HOST parameter and then a comment that say’s “99% chance you won’t need to change this value”. Well, guess what? You need to change this value. Change ‘localhost’ to ‘localhost:/tmp/mysql.sock’.
  4. Last step, throw your hands in the air and thanks the heavens (or curse the heavens… your call).

It took me about four hours to troubleshoot my way through this. I eventually found the problem buried deep within this tutorial (thanks, Warker!).

Categories: Macintoshery

This might turn into somewhat of a multi-parter as I’m finding myself becoming increasingly more enchanted with Fluid and the idea of site specific browsers in general (SSB). So, in this post, I would just like to introduce Fluid and the SSB concept.

In one sentence, I’d condense the SSB concept to the following: Confining a website to a single independent browser running as a stand-alone app. Yep. There you go. If I were to expand that into two sentences, I’d add: It feels like you’re running a website as a desktop app. The best way to visualize this is to use an example that many of us are probably familiar with: webmail. Imagine taking Gmail (or Yahoo! Mail… or (god forbid) Hotmail…) and turning it into a desktop application that you can launch in its own space, removed from the browser. Hot!

But why the heck would I even want to do that? Well, many of us (myself included) feel that certain web activities, like email, should be separate from other online activities, like shopping and the ambiguous, surfing (email, for me, and presumable many others, is a constant. If the computer is on, email is happening… not necessarily so with other activities). Using the SSB method, your webmail is now separate from other casual web use. You can close and open and interact with your browser without touching your email.

Okay, enough of that. What about Fluid? So Fluid is a Mac app that creates these SSBs (there are, I’m sure, PC equivalents… but I’ll leave it to another blogger to point to those). Just aim it at a URL and hit go! Next thing you know, you’ve got a brand new app sitting on your desktop (or wherever). It’s just about that easy. What makes Fluid so special though, is some of the other stuff that it can do… like support for custom icons (more on that later), plug-ins, user styles, and the ability to turn the whole dang SSB in to a menu bar app (definitely more on this in a future post)! Oh and if you are turning something like Gmail into an SSB, Fluid will auto-magically change it’s dock badge to reflect the number of unread messages in your inbox (if you’re SSBing Google Reader, it’ll do the same with unread posts)!

Alright, one more geeky thing to note and then we’ll call it a day: WebKit. WebKit is the open source rendering engine behind such browsers as Safari and the lesser known Omniweb and Shiira. Anyway, if the website works in Safari, it’s pretty much gaurunteed to work as a Fluid app because both are using the WebKit engine as their rendering platform.

Homework: Go get Fluid and build a site specific browser! Later, we’ll talk about tricking this thing out…

Tags: , , ,
Categories: Macintoshery

Need to type out the path to a file? Need to know where it lives? Sure, you could just think it through, but that takes… umm thought: “Okay… let’s see, users/scohen/library/… shoot, is that case sensitive?” Yeah, good luck with that. A better, easier, lazier thing to do is to simply drag and drop the file into a TextEdit window and copy the results.

  1. Open TextEdit (make sure you’re in plain text mode… Command+Shift+T toggles back and forth from plain text to rich text). A blank window should appear.
  2. Go find the file whose path you are too lazy to type out.
  3. Drag and drop it into the TextEdit window. TextEdit will inscribe the full path for you.
  4. Copy and paste.

Here comes some blurry video!

See, isn’t that so much easier than thinking? Don’t you think you should give me ten dollars?