Wednesday, 27 February 2008

Fixing Mac OS X Leopards abysmal PHP implementation

One of the unsung updates that occurred on OSX Leopard, was the introduction of Apache2 and PHP 5.2.4 as standard components for web page sharing. When you enable "Web sharing" on the Mac, you are essentially starting up a copy of the Apache workhorse on your system, enabled by OSX's unix underpinnings.

However in true Apple form, they seem to have gone out of their way to make life hard, and the default startup mode for the builtin apache system is as a 64bit application (on intel C2D+ hardware), making it difficult to use the provided PHP implementation "as is", if you need to load any extensions.

The issue stems from the choice of built in support on the Apple delivered php implementation. There are many deficiencies in the manifest of included options, of note is the lack of support for the PHP GD or GD2 module, used in many applications that required graphical output, PDFlib, libtidy and PEAR support are also highlighted by their absence.

Ok, no problem, down load the source for PHP 5.2.4. compile the extensions, and install them i hear you say....

Problem, on most recent Macs, the PHP implementation is also 64bit, a configuration that is not supported out of the box in the standard build options on PHP, and if that was not enough, many of the extensions you might want to install, are dependent on external libraries, not supplied by apple, and whose build environments also do not support creating the 4 way universal libs required to play nice across all the platforms Leopard runs on. Package managers such as fink or macports, hav'nt caught up with the need to supply 4 way fat binaries to cover all the possible platform variations.

Ok, no problem, I found this excellent tutorial on adding GD lib, , however try as i might, i could not get this to load, probaly again due to 64bit/32bit unhappyness. My foo is not enough........ :-( But it may work for you, and if GD is the only extension you need, then bobs your uncle.

Fortunately for those of use with more challenging PHP enviroment requirements Marc Liyange of http://entropy.ch fame has taken up the challenge and is producing a version of PHP 5.2.5 loaded for bear, which solves all of these build intricacies. Currently in beta 6, its works well on both my C2D macs and my G4 Macs.

However one word of caution, marc's installation process assumes that you have not yet enabled the on-board php implementation, if you have then you need to comment out the LoadExtension line you carefully uncommented to enable it, and trust to marc's magic installation of additional included conf files.

Oh, and another notable is that php.ini moves from /etc to /usr/local/php5/etc

More details of beta 6 can be found on this thread. http://www.entropy.ch/phpbb2/viewtopic.php?t=2945&start=0&postdays=0&postorder=asc&highlight=




No comments: