Upgrading PHP in MAMP
I wanted to take advantage of PHP 5.3′s new
1 | namespace |
feature but in my localhost environment, I use MAMP. Upgrading PHP proved a little tricky, but actually very easy. The tricky part was figuring out how to make it work, but on the whole, it’s not too bad.
First, run the
1 | phpinfo() |
function in a PHP script on your localhost or go to PHPMyAdmin and hunt down the configuration page. You should see a large chunk of configuration markup at or near the top:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 './configure' '--with-mysql=/Applications/MAMP/Library'
'--with-apxs2=/Applications/MAMP/Library/bin/apxs'
'--with-gd' '--with-jpeg-dir=/Applications/MAMP/Library'
'--with-png-dir=/Applications/MAMP/Library' '--with-zlib'
'--with-freetype-dir=/Applications/MAMP/Library'
'--prefix=/Applications/MAMP/bin/php5' '--exec-prefix=/Applications/MAMP/bin/php5'
'--sysconfdir=/Applications/MAMP/conf/php5' '--with-soap'
'--with-config-file-path=/Applications/MAMP/conf/php5'
'--enable-track-vars' '--enable-bcmath' '--enable-ftp' '--enable-gd-native-ttf'
'--with-bz2=/usr' '--with-ldap' '--with-mysqli=/Applications/MAMP/Library/bin/mysql_config'
'--with-sqlite' '--with-ttf' '--with-t1lib=/Applications/MAMP/Library'
'--enable-mbstring=all' '--with-curl=/Applications/MAMP/Library' '--enable-dbx'
'--enable-sockets' '--enable-bcmath' '--with-imap=shared,/Applications/MAMP/Library/lib/imap-2006i'
'--enable-soap' '--with-kerberos' '--enable-calendar'
'--with-pgsql=shared,/Applications/MAMP/Library/pg' '--enable-dbase'
'--enable-exif' '--with-libxml-dir=/Applications/MAMP/Library'
'--with-gettext=shared,/Applications/MAMP/Library' '--with-xsl=/Applications/MAMP/Library'
'--with-pdo-mysql=shared,/Applications/MAMP/Library' '--with-pdo-pgsql=shared,/Applications/MAMP/Library/pg'
'--with-mcrypt=shared,/Applications/MAMP/Library' '--with-openssl'
Copy and paste this whole chunk into your text editor and remove the single quotes (search and replace should do it). Look for the flag
1 | --with-pdo-mysql=shared,/Applications/MAMP/Library |
and replace it with:
1 --with-pdo-mysql=/Applications/MAMP/Library
If you don’t do this, you might end up with an
1 | ld: symbol(s) not found |
error.
Finally, add the following flag to the end:
1 --without-iconv
After you have downloaded the latest PHP release of your choosing from PHP Sources Snapshots,
1 | cd |
to the downloaded directory in Terminal. Paste your reformatted configuration string (all of it, including the beginning
1 | ./configure |
command) and run it.
After the configuration phase is finished, run:
1
2 $ make
$ sudo make install
Relaunch MAMP, and you’re good to go.
For you CakePHP users out there, now you can play with Cake3 releases (which apparently will be optimized for PHP 5.3+).
Using Cappuccino with CakePHP
If you haven’t given Cappuccino a look, you ought to. It’s a JavaScript framework designed after Apple’s Cocoa framework for building web applications. You wouldn’t use Cappuccino to build informational web sites, or really anything other than a web app, but for web apps it rocks. All of the HTML, DOM, and JavaScript is abstracted out and substituted instead is one language that handles all the heavy lifting for you: Objective-J.
Objective-J is a superset of JavaScript much like Objective-C is to C. If you’re already familiar with Objective-C, you should find Objective-J a cinch. And if you’re like I was and come out of a PHP, HTML background, it’s still simple to learn (with a little bit of patience).
Cappuccino mainly runs as a client-side framework, meaning that most of the functionality and coding happens without talking to the server. This doesn’t mean that it can’t communicate with the server; on the contrary, it works like you’d expect with other JavaScript frameworks like JQuery or Prototype, but it does so with its own Objective-J flavor. The handling is superb, allowing you to essentially Cocoa-ify the web browser without worrying about cross-browser compatibility and lots of hard coding. When going back and forth between server-side scripting and Cappuccino, all you have to do is send data in JSON format and Cappuccino can handle the rest of your needs.
On the Server: CakePHP. In the browser: Cappuccino.
I wanted to combine the powers of Cappuccino and CakePHP, but it required a little bit of configuring to get it working correctly. I’ll outline the steps I took to get Cappuccino working with Cake. Let’s start with a basic Cake application running out of the box, no controllers or anything. I’m using the standard directory structure for a Cake app that’s running correctly.
Step 1: Load the Cappuccino Libraries. Once you’ve downloaded the Cappuccino starter package, you’ll see a folder called “NewApplication.” Rename this to “cappuccino” and copy it to the Cake app’s
1 | webroot/js |
directory. All of your Cappuccino programming will happen in this folder. We just need to tell Cake to run the Cappuccino app.
Step 2: Create the Layout. Create
1 | views/layouts/default.ctp |
and copy and paste the markup from the starter index.html file here. Select all in the
1 | webroot/js/cappuccino/index.html |
file and paste it in this default layout file.
Step 3: Configure the Layout. You should notice a
1 | <script> |
area that contains a JavaScript environment variable named
1 | OBJJ_MAIN_FILE |
. This main file won’t run out of the box now that we’re calling this view from within CakePHP. All we have to do is add the
1 | <base> |
tag and let Cake provide the correct path, and it should line all of the libraries up correctly. Replace the code within this script area with the following:
1
2
3 1 var path = "<?=$html->url('/js/cappuccino/',true);?>";
2 document.write("<base href=\"" + path + "\"><!- -[if IE]><"+"/base><![endif]- ->");
3 OBJJ_MAIN_FILE = "main.j";
Notice that on line 1, I use the HTML helper’s URL function to provide the path as an absolute URI. Line 2 addresses an IE inconsistency (any surprise there?) regarding the base tag. Line 3 is the same OBJJ_MAIN_FILE parameter that is included in the starter index.html Cappuccino file.
Step 4: Launch the App. Now just call your Cake application in the web browser, and you should see “Hello World” execute appropriately.
Adjusting this Setup
You may want to use Cappuccino in only some CakePHP actions. If that’s the case, then create a different layout file, something like
1 | cappuccino.ctp |
, then call this layout only in the actions that you want to use Cappuccino. The following
1 $this->layout = 'cappuccino';
is used in the controller actions to then switch to this Cappuccino-based layout.
Remember that Cappuccino will come first in the code hierarchy now that we’ve got it installed. In other words, if you want Cake to provide content for these Cappuccino views, you’ll need to get Cappuccino first to run GET or POST requests using Cake routes. Then, you’ll need to change your output from HTML to JSON when talking back, unless you have segments of your Cappuccino app that are meant to display HTML output. But that’s a subject for another day. Take a look at Nice Panorama’s Tutorial Demos to get a sense of what I mean by this.
Phase In, Phase Out
So 2009 has been a whirlwind for all of us. The global economy has gone to pot and many of us are struggling mightily to make ends meet. As for me, I have the benefit of laying low, kinda. I’ve been hard at work pursuing a graduate degree, and since this is a necessary step in my professional aspirations, now is perhaps the best time to be chugging away at schoolwork rather than taking the job market head-on. What this has meant, though, is more or less a hiatus from the full-steam-ahead web development work of 2008. And this blog has been quiet as well.
But students are not immune from ailing economies. Funding has dried up all over the place. My particular university noticed a drop of around a third in their endowment fund. So just as I was phasing out of web work to embark in more academic pursuits, I have found myself falling back and relying heavily on web development to get me through. I have more to blog about, more CakePHP to discuss, and hopefully more screencasts to film.
As a blog-warming gift to those readers who have stuck around, here’s a handy PHP script I wrote for managing 2-way encryption for credit card numbers. Like anything in data security, it’s not completely bulletproof, but I think I’ve managed a moderately to highly secure algorithm here that allows one to hold onto credit card numbers in an encrypted form, and still decipher those numbers for later processing. Of course, there’s no replacement for overall site security, so be sure to install this file outside the server root, and take care of those database calls so that you forestall any intrusion hacks.
A test credit card number from American Express:
1 371449635398431
encrypts as:
1 snRLL^AN+HtsBi3$J)sHpLsRG
Of course, by altering some settings, that same number can come out even longer:
1 a<:8aaaUTE)TR(/%dL7[?kLe0_Gry@ZR{bTaB!~E3arALaRL
Installation is pretty easy. Just include the script, instantiate the
1 | DGCrypt |
class, and run either
1 | encode() |
or
1 | decode() |
. Be sure to edit the class properties with your own values, or your salt values will be compromised.
Encrypting a number
1
2
3
4
5 include_once(PATH_TO_FILE.DIRECTORY_SEPARATOR.'dgcrypt.php');
$cc = new DGCrypt();
$encryptedNumber = $cc->encode($_POST['credit_card']);
//save $encryptedNumber
Decrypting a saved string
1 echo $cc->decode($encryptedString);
Download
So here it is. One file, nice and easy. Enjoy, and best of luck to everyone in your pursuits.

