Urania

A blog named for the muse of Astronomy containing musings by an astronomer

Making Leopard PHP a better PHP by adding GD support

Posted on March 04, 2008 by Juan
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.]

1 Trackbacks/Pingbacks

  1. 10 04 08 16:33

    Urania » Blog Archive » osxutils now fixed on MacPorts under Leopard

7 to “Making Leopard PHP a better PHP by adding GD support”

  1. Mr K says:
    Hey there great post ... a question for you. how did you update PHP on leopard from 5.2.4 to 5.2.5?? Is it easy enough to do? A step by step tutorial would be awesome if you had the time. It seems the 5.2.4 that comes with Leopard is also missing things like mcrypt & pdo_mysql
  2. Juan Cabanela says:
    Unfortunately, I have been unable to get PHP 5.2.5 to compile properly in Leopard, despite trying some tricks like re-installing/upgrading Apache and the like. PHP 5.2.5 just throws a slew of errors in its 'make test' phase when I attempt to get it working, so I have given up on upgrading to it for now.
  3. Jeff Parsons says:
    It looks to me like Apple's recent security update (2008-002), which updates PHP to 5.2.5, has bundled GD support into the PHP apache module. That's good news, except for one small detail: the CLI version of PHP 5.2.5 that they've provided does NOT appear to include GD support. So when I run any PHP tests using the command-line interface, I still have to use a home-built version of PHP. Also, I suspect the reason many people have been unsuccessful building their own PHP for Leopard is because Leopard needs a 64-bit version of PHP -- in part because the OS shipped with a 64-bit version of apache. I recommend building just the GD library, rather than all of PHP, and continue using the pre-installed PHP. Before the 2008-002, I was able to do that as follows:
    
    cd php-5.2.4/ext/gd
    phpize
    MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp
    " CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch 
    x86_64 -g -Os -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure --with-zlib-dir=/
    usr --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/X11R6 --with-freetype-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6
    make
    sudo make install
    sudo echo "extension=gd.so" >> /etc/php.ini
    sudo apachectl restart
    
    I haven't tried this procedure again with the 5.2.5 PHP sources and 2008-002 security update, however.
  4. Jeff Parsons says:
    Fyi, the above steps do still work with 2008-002 and PHP 5.2.5. Also, I remembered those steps came from: osx.topicdesk.com
  5. Serge says:
    Unfortunatelly, Hill Pei's link is down, and I can't find this page in google's cache 🙁 However, judging by other sites, this method requires xCode preinstalled, doesn't it?
  6. admin says:
    Yes, any attempt to compile new features into a Mac programming language will generally require you to install the C compilers that come with XCode since many programming languages are written in C.
  7. admin says:
    I fixed the broken link to Hill Pei's old website to point to what I believe is either a copy of the site or just the site he moved the content to.


Leave a Reply


  • Translate

  • Astro Pic o' the Day

  • Archives

  • Admin



↑ Top