Snow Leopard

Installing PHP 5.2.10 on OS X 10.6 Snow Leopard

Since my update to Snow Leopard, I was pleasantly surprised to find that Apple has updated PHP to version 5.3 and also included the GD extension. While I no longer have to rebuild the extension manually like on Leopard, these changes to PHP brought around a different problem: Drupal is currently not compatible with PHP 5.3 (#360605).

I've been trying to get my local Drupal installations working, and although the patch from post #84 works pretty well (when applied to a D6 CVS checkout), Ubercart is still nonfunctional. Since I am currently building and testing Ubercart-enabled sites, my only remaining option was to downgrade to PHP 5.2.10. I wanted to have the same extensions and options that Apple's PHP 5.3 build had, so I started by viewing the output of phpinfo() and copying the configure command. To compile PHP, locally installed copies of libpng, libjpeg and pcre are required so let's started with that:

  1. (Like in the Leopard tutorial, I assume you have installed the Xcode & related developer utilities and that all downloads are saved in the "Downloads" folder in your home). Visit the libpng, libjpeg and PCRE homepages and download the latest release available for both. As of writing, the most recent releases are libjpeg 7, libpng 1.2.39 and PCRE 7.9.
  2. Compile libpng and libjpeg statically:
    cd ~/Downloads && tar xfz libpng-1.2.39.tar.gz
    cd libpng-1.2.39
    ./configure --disable-shared --enable-static
    make && make install DESTDIR=`pwd`/localinstall

    cd ~/Downloads && tar xfz jpegsrc.v7.tar.gz
    cd jpeg-7
    ./configure --disable-shared --enable-static
    make && make install DESTDIR=`pwd`/localinstall

    cd ~/Downloads && tar xfj pcre-7.9.tar.bz2
    cd pcre-7.9
    ./configure --disable-shared --enable-static
    make && make install DESTDIR=`pwd`/localinstall
  3. Since PHP will be built with MySQL support, download and install MySQL x86_64 for OS X. As of writing, the latest version is 5.1.38.
  4. Download PHP 5.2.10, available here
  5. Next, PHP needs to be prepared for compilation. As detailed in PHP bug #49267, a small change is required to get PHP to compile on Snow Leopard:
    1. Type in the terminal:
      cd ~/Downloads && tar xfj php-5.2.10.tar.bz2
      cd php-5.2.10
      nano ext/iconv/iconv.c
    2. Skip down to line 185 (Tip: <ctrl+c> shows current line)
    3. Remove the lib on #define iconv libiconv so that the code reads like this:
      #ifdef HAVE_LIBICONV
      #define iconv iconv
      #endif
    4. Hit <ctrl+o> and to save the file
    5. Hit <ctrl+x> to quit nano
  6. Now, PHP is ready for compilation. We will use a configure command relatively similar to the command extracted from phpinfo() earlier:
    ./configure '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--sysconfdir=/private/etc' '--with-apxs2=/usr/sbin/apxs' '--enable-cli' '--with-config-file-path=/etc' '--with-libxml-dir=/usr' '--with-openssl=/usr' '--with-kerberos=/usr' '--with-zlib=/usr' '--enable-bcmath' '--with-bz2=/usr' '--enable-calendar' '--with-curl=/usr' '--enable-exif' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/Users/shortname/Downloads/jpeg-7/localinstall/usr/local' '--with-png-dir=/Users/shortname/Downloads/libpng-1.2.39/localinstall/usr/local' '--enable-gd-native-ttf' '--with-ldap=/usr' '--with-ldap-sasl=/usr' '--enable-mbstring' '--enable-mbregex' '--with-mysql=/usr/local/mysql/' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-mysql-sock=/tmp/mysql.sock' '--with-iodbc=/usr' '--enable-shmop' '--with-snmp=/usr' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-xmlrpc' '--with-xsl=/usr' '--with-pcre-regex=/Users/shortname/Downloads/pcre-7.9/localinstall/usr/local'

    EXTRA_CFLAGS="-lresolv" make -j2
    Remember to replace shortname in /Users/shortname to your system account's shortname. If you're not sure what that is, type whoami in a terminal to find out.
  7. Finally, backup Snow Leopard's PHP extension so that PHP 5.3 can be restored later, and copy the PHP 5.2.10 extension in its place:
    sudo mv /usr/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.so.orig106
    sudo cp libs/libphp5.so /usr/libexec/apache2/libphp5.so
  8. The final step is to restart Apache - this can be done by toggling Web Sharing in System Preferences, or alternatively via the apachectl command:
    sudo apachectl restart
  9. That's all! Now run phpinfo() and verify that PHP 5.2.10 is up & running. While I was trying to get this working, I stumbled accross two compile errors - for the sake of completeness, I've listed them below along with the failure cause:

    1. This error occurs if EXTRA_CFLAGS="-lresolv" is not used while compiling PHP:
      Undefined symbols:
        "_res_9_dn_expand", referenced from:
            _zif_dns_get_mx in dns.o
        "_res_9_search", referenced from:
            _zif_dns_get_mx in dns.o
            _zif_dns_check_record in dns.o
        "_res_9_dn_skipname", referenced from:
            _zif_dns_get_mx in dns.o
            _zif_dns_get_mx in dns.o
      ld: symbol(s) not found
      symbols:
        "_res_9_dn_expand", referenced from:
            _zif_dns_get_mx in dns.o
        "_res_9_search", referenced from:
            _zif_dns_get_mx in dns.o
            _zif_dns_check_record in dns.o
        "_res_9_dn_skipname"collect2: , referenced from:
            ld returned 1 exit status_zif_dns_get_mx
      in dns.o
            _zif_dns_get_mx in dns.o
      ld: symbol(s) not found
      collect2: ld returned 1 exit status
    2. This error occurs if the #define iconv libiconv is not changed to #define iconv iconv
      Undefined symbols:
        "_libiconv", referenced from:
            __php_iconv_strlen in iconv.o
            _php_iconv_string in iconv.o
            _php_iconv_string in iconv.o
            __php_iconv_strpos in iconv.o
            __php_iconv_appendl in iconv.o
            __php_iconv_appendl in iconv.o
            _zif_iconv_substr in iconv.o
            _zif_iconv_mime_encode in iconv.o
            _zif_iconv_mime_encode in iconv.o
            _zif_iconv_mime_encode in iconv.o
            _zif_iconv_mime_encode in iconv.o
            _zif_iconv_mime_encode in iconv.o
            _zif_iconv_mime_encode in iconv.o
            _php_iconv_stream_filter_append_bucket in iconv.o
            _php_iconv_stream_filter_append_bucket in iconv.o
      ld: symbol(s) not found
      collect2: ld returned 1 exit status
Rating: 

Boot Camp 3.0 + Windows XP Service Pack 3 = installation error

Seeing as I completely reformatted my MacBook Pro's hard disk, I also had to reinstall Windows via Boot Camp 3.0 today. Everything went well, however when the time came to install Service Pack 3 (my copy of XP is an SP2 OEM disc), I received an odd error I had never seen before:

An error occured while copying file osloader.ntd.  Cannot copy file to destination directory.  Click Retry to retry the operation or click Cancel.

A Google revealed that this error is caused by an Apple's new HFS+ drivers for Windows, as detailed here. Simply following the instructions and renaming the driver fixes the problem. After installing SP3, I restored the HFS+ driver to it's original state and all is well.

Rating: 

OS X 10.6 (Snow Leopard)

I just installed Snow Leopard and I must say that I am very impressed. Apple has once again done an excellent job and rounded off the rough edges on Leopard, which was already a pleasure to use.

Although Apple recommends doing an upgrade install over a clean install, I opted for a clean install because I've modified various parts of my OS X Leopard installation over time (installed Python 2.6 over 2.5, installed KDE for OS X, a few MySQL installations/upgrades, etc) and I wanted to try a fresh start of OS X. Formatting the hard disk took and the installation was about half an hour from start to finish, and I was able to use my new system as soon as the Snow Leopard installer rebooted the machine for me.

One of the first things I noticed was that everything was much more snappy compared to Leopard. Everything I do seems more responsive while using Snow Leopard; all of the small lags or delays (while restoring a minimized window, for example) are gone. On the other hand, more intensive tasks like opening a large application or restarting the machine are noticeably faster. Phoronix released an article today comparing the performance of Snow Leopard (OS X 10.6) vs Leopard (OS X 10.5), and at first glance it seems like OpenGL performance has dropped a bit, but otherwise there are enhancements all around.

I was a bit worried as I was upgrading because I had read this document describing that certain (popular) software titles were incompatible and would not open on Snow Leopard. As it turns out, I had no problems at all with any of my software. All of the software I was using with OS X 10.5 works perfectly with OS X 10.6, including Thunderbird 3.0b3, MacFUSE+NTFS-3G, Starcraft and OpenOffice.org. It should be noted that for Starcraft and other PPC-based applications to work, you need to install Rosetta from the Optional Installs of the Snow Leopard installation DVD.

So if you're reading this on a Mac with OS X 10.4 (Tiger) or 10.5 (Leopard), I recommend that you grab a copy of Snow Leopard the next time you are nearby an Apple store or reseller. Snow Leopard is being sold at $35 for a single license or $55 for the family pack (5 licenses for use in one household) and the feature and performance enhancements it brings are well worth it.

For what it's worth, one of the changes I particularly like is how Snow Leopard reports disk size, which as documented here, has changed. All tools in Snow Leopard now report disk size using base 10 measurements, meaning a 200GB hard drive appears in your system as 200GB and not 186.26GB. I'm glad that somebody has finally made a move, because users - myself included - honestly don't care if a GB is 1024 or 1000 MB. That is irrelevant. What does matter is that the measurement doesn't change in one context and another. Otherwise, it isn't much of a standard measurement, right? It would be ridiculous to propose that the same unit "kilometre" represented a different distance depending on if you walked or drove from point A to B, but essentially that is what has happened in the computer industry. Depending on if you are shopping for or writing information to a storage medium, its size changes with the same unit. It's pretty odd to explain that when someone asks "where has the remaining 300MB gone on my 4GB USB key? I only see 3.7GB."

Rating: