Archive for March 4th, 2008

Making Leopard PHP a better PHP by adding GD support

Command Line Tricks, MacOS X Annoyances 5 Comments »
The nice thing about MacOS X 10.5 Leopard is that it comes with PHP 5.2.4 pre-installed. Unfortunately one of the features Apple choose not to compile in was support for the GD graphics library, which I use extensively. Furthermore compiling in new features has proven to be somewhat troublesome. When I tried to configure PHP 5.2.5 on my Leopard box which the following commands (a variant of the configure command I would issue under Tiger with no complaints):
./configure --prefix=/usr --mandir=/usr/share/man 
   --infodir=/usr/share/info --disable-dependency-tracking 
   --with-apxs2=/usr/sbin/apxs  
  --with-ldap=/usr --with-kerberos=/usr 
   --enable-cli 
   --with-zlib-dir=/usr 
   --enable-trans-sid 
   --with-xml 
   --with-dom 
   --enable-exif 
   --enable-ftp 
   --enable-mbstring 
   --enable-mbregex 
   --enable-dbx 
   --enable-sockets  
  --with-iodbc=/usr 
   --with-curl=/usr 
   --with-iconv=shared,/opt/local
   --with-openssl=shared,/opt/local
   --with-xmlrpc 
   --with-xsl=/usr 
   --with-config-file-path=/etc 
   --sysconfdir=/private/etc 
   --with-gd=/opt/local --enable-gd-native-ttf 
   --with-jpeg-dir=/opt/local 
   --with-tiff-dir=/opt/local 
   --with-png-dir=/opt/local 
   --with-freetype-dir=/usr/X11 
   --with-xpm-dir=/usr/X11 
   --with-pdflib=/opt/local 
   --with-gettext=/opt/local
   --with-mysql=/usr/local/mysql 
   --with-mysqli=/usr/local/mysql/bin/mysql_config 
   --with-pdo-mysql=/usr/local/mysql 
   --without-pear
The result was a failed configure due to an error in mysql configuration. I pinned this down to a request for a library at /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib which is actually located one directory up. This can be fixed via the command line using:
cd /usr/local/mysql/lib
mkdir mysql
cp libmysqlclient.15.dylib mysql/libmysqlclient.15.dylib
Then the ./configure worked just fine. Unfortunately, when I did a
make
make test
to compile the PHP and test it, there was no happiness. There were over 50 errors, some of them major. Crud. This is just the setup. See, all I needed was GD graphics library support in PHP for my website. Well, after googling for some time for some master hacker’s notes on getting PHP 5.2.5 to compile on Leopard, I discovered a fellow named Hill Pei had hacked GD support into the Leopard PHP without too much effort. His method simply requires some comfort with the command line and editing text files. In five minutes, I had GD support with Leopard’s built-in PHP. Excellent! [Despite a report in the comments to the contrary. This still appears to be necessary if you apply Security Update 2008-002, which installs PHP version 5.2.5. In which case, you should grab the php 5.2.5 code and work from there. I can confirm Hill Pei's instructions do work after Security Update 20008-002 if you grab the PHP-5.2.5 code instead of 5.2.4 as he suggests.]

Site upgrade to Leopard

Astronomical Software, MacOS X, MacOS X Annoyances, MacPorts, X11 No Comments »

I have taken part of my day to get my main web server upgraded to MacOS X 10.5 (aka Leopard). I spent quite a bit of time waiting, removing programs I knew were incompatible, and so on. Still, this upgrade was not without a few bumps:

  • Check Hardware Compatibility: My Sonnet Tempo SATA X4P card (which I use to provide an external SATA [eSATA] interface for my RAID of data drives) was incompatible with Leopard and would cause the installer to hang. I finally discovered a firmware upgrade was available that fixed this. This was a stupid rookie mistake. Rule of Thumb: Always check the non-Apple hardware for updates before making a major OS X upgrade.
  • Watch out for /home: I had been using a symbolic link from /home to /Users because in my old Unix days, I hardcoded a lot of my software to look for my home directory in /home. Leopard expects /home to be available as mount point for the automount service, so getting with the modern era and not relying on /home to point to /User is required if you adopt Leopard.
  • Rebuild Web Server Configuration: One problem I was prepared for is that the web server was updated to Apache2. This in itself was not bad, but the configuration files for Apache (version 1) were stored in /etc/httpd and the new configuration files for Apache2 are in /etc/apache2 and they were NOT migrated. I don’t fault Apple for not migrating the files, but I kicked this around on my laptop quite a bit in order to tweak the configuration files back to something I liked. One thing I immediately did was that this MacOS comes with PHP 5.2.4 preinstalled, but not enabled in Apache2. I enabled it by editting the /etc/apache2/httpd.conf file (which you might have to create) and uncommenting the line with # LoadModule php5_module (by removing the ‘#’ symbol from the beginning of the line). Once that was done, I restarted the Apache2 server and all my PHP code (including this blog) was running again.
  • Tweak MySQL for Leopard: The PHP 5.2.4 included with MacOS X is compiled with support for MySQL. This is nice in that you can just download the MySQL package installer and quickly get a LAMP server running. However, it was set up with the MacOS X Server version of MySQL in mind, which means it expects the socket to be in a different location than the vanilla MySQL. This can be solved by either tweaking the MySQL configuration (as outlined in the MySQL section of the blog post at http://remysharp.com/2007/10/27/lamp-in-leopard-osx-105-php5-and-apache-22/ ) or by tweaking the PHP configuration by editing the /etc/php.ini file (if it doesn’t exist, first copy /etc/php.ini.default to /etc/php.ini) and search for the line containing mysqli.default_socket = to read
    mysqli.default_socket = /private/tmp/mysql.sock
    
    This solution seemed more straight forward, so I did this.
  • Reinstall MacPorts: Since I am aficionado of MacPorts, I reinstalled it and rebuilt all the ports. Some of the issues I had before with MacPorts on Leopard on my MacBook Pro cropped up again on my PowerMac G5, notably
    • gv still needs to be patched as I noted here.
    • sqlite3 still does know about its dependence on nawk.
    • xterm doesn’t install unless you update your X11 installation using the latest version of Xquartz (currently at version 2.1.4).
  • Update to latest version of Xquartz: Since I don’t like X11 headaches, I updated to the latest version of Xquartz (currently at version 2.1.4).

So the adventure continues. Back to research, I have invested about 5 hours of my spring break into this upgrade, that is enough for now.