Upgrading to Lion and problems with PHP, MySQL, etc.

The upgrade to OS X 10.7 was relatively painless. That is, until I starting doing some more local web development. Here’s the list of problems I found — and solutions — with the hopes that it’ll help others.


  • The config files in /etc/apache/ changed a bit, with the result being I couldn’t get mod_rewrite to work.  The solution seemed to be to restore everything from /etc/apache/original/*.conf, then tweak as required for local fixes.  Also, be sure to uncomment the PHP module lines from httpd.conf.
  • /etc/php.ini doesn’t exist.  Your previous php.ini is now /etc/php.ini-5.2-previous or something similar.  Again, copy that file back, or use the /etc/php.ini.default and adjust accordingly


  • I took advantage of this downtime to also upgrade MySQL, using the official packages at http://dev.mysql.com/downloads/mysql/ (hint: use the Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive file).  Before you do, either dump all your existing databases so you can reimport them after, or be prepared to move the contents of /usr/local/mysql-5.1.52-osx10.6-x86_64/data to /usr/local/mysql-5.5.19-osx10.6-x86_64/data (or whatever your old and the current versions are) and chown/chmod them accordingly.
  • Also, at some point along the line, the config option skip-locking was renamed to skip-external-locking, so change that in /etc/my.cf.  Also, it seems InnoDB isn’t even included, so the line skip-innodb needs to be commented out (if you have it).  Check /usr/local/mysql/data/hostname.err for other problems if you can’t get the server to start.


  • I had these installed in /usr/local/lib/php, but it seems the “right way” is to put them in /usr/lib/php/pear.  Also, any PECL extensions will need to be recompiled for the new version of PHP
  • The instructions at http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-7-lion/ are pretty helpful
  • Note that you’ll need Xcode installed to compile PECL extensions.  Go to the App Store for it, and brew yourself a tea while you wait for the download to complete.

Those seem to be all the “gotchas” … for now at least.

Javascript String.reverse and String.translate

The comment about obfuscating email addresses led me to look for Javascript functions that reverse a string, or translate characters á la PHP’s strtr() function.

Of course, they don’t exist natively, so here are my versions that extent the String class:

String.prototype.reverse = function() {
	var str='';
	for (i=this.length-1;i>=0;i--) {
		str += this.charAt(i);
	return str;

String.prototype.translate = function(from,to) {
	var sl = this.length,
		tl = to.length,
		xlat = new Array(),
		str = '';

	if (sl<1 || tl<1) return this;

	for (i=0; i<256; xlat[i]=i, i++);

	for (i=0; i<tl; i++) {
		xlat[ from.charCodeAt(i) ] = to.charCodeAt(i);

	for (i=0; i<sl; i++) {
		str += String.fromCharCode( xlat[ this.charCodeAt(i) ] );

	return str;


var msg = 'Hello world!';

The code for the translate() method was copied from the PHP source code. If there are more efficient ways to do it, feel free to comment!


Schedule_At was a PEAR class I wrote in 2003. It was a quick, hack-y interface to the command-line at scheduler from within PHP.

Based on an email query I received today, I’m making it directly available here. Enjoy!


Email Protection with JQuery

I’ve been using Prototype.js and script.aculo.us quite a bit on any sites I’ve done lately. I remember way back when Javascript and DHTML-goodies were a dark art, and getting that drop-down menu working just right was a huge relief. Well, these two tools have been a time-saver.

As it turns out, I couldn’t get one particular drop-down menu fade-in/out to work with Prototype/Script.aculo.us … so I decided to take a look at one of the other Javascript frameworks out there: jQuery. In no time, I had things working the way I wanted.

I got to thinking again (as I have before) about disguising email addresses on web pages, so that users can read and follow mailto: links easily, but evil robots can’t scrape your site and eventually spam you.

Using jQuery, this would appear to be pretty easy.

First, structure your links like so:

[cc lang="html4strict"]


Then, in the head of document, add the following javascript code:

[cc lang="html4strict"]


Basically, after the the page loads but before it renders, this function looks for all anchor tags of class=”email”. For each of them, it parses the rel attribute, replacing the slash with an at-sign. Then it changes the href to the correct mail link, and inserts the address inside the tag.

In my opinion, you’d need a fair bit of robot mojo to decode this.

One drawback is that it doesn’t degrade nicely for people without javascript … although I’m working on a possible solution (hint, read this old article for the inspiration).

Any thoughts?

I’m Still Alive

I just realized it’s been a year since I posted here. Yikes!

I am still among the living, don’t worry. I’ve gone through a bit of a career change and am actually back at school pursuing something I’ve always been interested in.

That said, I haven’t been doing much coding or design work lately. A few business cards here, a bit of custom CMS stuff there. Playing around with AJAX is fun (and yes, sooo 2006, I know). Look for a few new projects in the near future.

Speaking of … one of my current projects, Green Garage has been getting my recent attention, so most of my posts are over there.

Talk soon!

Posted in Life | Comments Off

MySQLi in PHPAdsNew 2.0.7

Here is a quick patch for users of PHPAdsNew who are running their site on PHP5 and MySQL 4.1.

PHP5 introduced support for an enhanced MySQL 4.1 library called MySQLi. If you’ve compiled in MySQLi support into your copy of PHP (using --with-mysqli=/path/to/mysql_config), then you should use the newer, more efficient MySQLi functions to access the database.

Benefits of MySQLi include much faster queries and, in my experience, much fewer open connections between PHP and the MySQL server. On the ad server I administer, we went from an average of 600 running processes to around 16, with no degradation in performance.

Here is the patch against PHPAdsNew 2.0.7. Enjoy!


Posted in PHP | Comments Off

Job’s Ace

Unless you’ve been living under a rock, you’ve all heard about the new iPod from Apple.

[Side note: I’m not going to call it a “video iPod” as every one else seems to. To do so would seem to suggest that there are non-video iPods. There aren’t. Apart from the Shuffle and the Nano (which, since it’s flash memory based, wouldn’t be a candidate for video anyway, I imagine), the only new iPod you can buy now is one with the ability to play video. That’s it. It’s a feature, not a differentiator.]


You’ve also heard that you can download, for $1.99, episodes of several television shows from the iTunes Music (and now Video) Store the day after they aired on TV.

Everyone says this is going to be The Next Big Thing, a kick in the pants to the entire media world.

It probably is.

But the bigger kick in the pants will be when you can start downloading the day before they air.

Now that is what’s going to change things.

Posted in Mac | Comments Off