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:
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
cd ~/Downloads && tar xfj php-5.2.10.tar.bz2
cd php-5.2.10
nano ext/iconv/iconv.clib on #define iconv libiconv so that the code reads like this:#ifdef HAVE_LIBICONV
#define iconv iconv
#endif./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.
sudo mv /usr/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.so.orig106
sudo cp libs/libphp5.so /usr/libexec/apache2/libphp5.sosudo apachectl restartThat'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:
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#define iconv libiconv is not changed to #define iconv iconvUndefined 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 statusI play around with a number of Drupal locally and today I finally caved in and decided to add GD support to OS X's webserver. Although I've heard great things about the Entropy PHP packages, I did not want to replace OS X's integrated php installation so my remaining option was to grab a copy of PHP 5.2.8 (the version bundled with Leopard) and compile the module myself. I know there must be quite a few other people who are looking do to the same thing, so I here's a step-by-step guide on how I did it:
(Please note that I assume you have Xcode installed, and that all downloads are saved in the "Downloads" folder in your home. If this is not the case, please move the downloads there first before executing any of the listed commands)
cd ~/Downloads
tar xfj php-5.2.8.tar.bz2
cd php-5.2.8/ext/gd
mv ~/Downloads/libpng-1.2.37.tar.gz ~/Downloads/jpegsrc.v7.tar.gz .tar xfz libpng-1.2.37.tar.gz && cd libpng-1.2.37
./configure --disable-shared --enable-static
make && make install DESTDIR=`pwd`/localinstall
cd ../tar xfz jpegsrc.v7.tar.gz && cd jpeg-7
cp /usr/share/libtool/config.* .
./configure --disable-shared --enable-static
make && make install DESTDIR=`pwd`/localinstall
cd ../cd ~/Downloads/php-5.2.8/ext/gd
phpize
MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS="-O3 -fno-common -arch i686" \
LDFLAGS="-O3 -arch i686" \
CXXFLAGS="-O3 -fno-common -arch i686" \
./configure --with-zlib-dir=/usr \
--with-png-dir=`pwd`/libpng-1.2.37/localinstall/usr/local \
--with-jpeg-dir=`pwd`/jpeg-7/localinstall/usr/local \
--with-freetype-dir=/usr/X11R6 \
--with-xpm-dir=/usr/X11R6
make
sudo make installsudo nano /System/Library/LaunchDaemons/org.apache.httpd.plist<array>
<string>/usr/bin/arch</string>
<string>-i386</string>
<string>/usr/sbin/httpd</string>
<string>-D</string>
<string>FOREGROUND</string>
<array>This will ensure that Apache starts in 32 bit mode, which is needed as the gd extension was compiled for i686.
That's all! After a reboot (or toggle Web sharing in the System Preferences), everything should be working. phpinfo() should now confirm that GD library is indeed loaded. If it isn't or if apache refuses to start, try opening Console to check /var/log/apache2/error_log for some useful pointers as to what's wrong.
Helpful source I used for writing this tutorial: HOWTO: Install Habari on Mac OS X Leopard, From Scratch