在 Snow Leopard 上编译 php-5.2.8

Snow Leopard 中带的 PHP 是 5.3 的,有点太超前了,还是 php-2.x 用着比较习惯,不过 2.x 版的 php 在 SL 中编译起来有点麻烦,需要手工改 Makefile 才能正确编译(主要就是 libiconv 这个库的问题)。

折腾到半夜,终于搞定了,记录一下:

1. 先用 port 安装一些依赖的库
sudo port -v install t1lib jpeg libpng libmcrypt libxml2 gettext curl

2. configuration
CFLAGS="-arch x86_64 -I/opt/local/include/" LDFLAGS="-L/opt/local/lib" \
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-openssl=shared,/usr \
--with-zlib=/usr \
--with-zlib-dir=/usr \
--with-xpm-dir=shared,/usr \
--with-gd \
--with-ldap=shared \
--with-xmlrpc \
--enable-exif \
--enable-soap=shared \
--enable-sqlite-utf8 \
--enable-wddx=shared \
--enable-ftp=shared \
--enable-sockets \
--with-bz2=shared,/usr \
--enable-zip=shared \
--enable-pcntl \
--enable-shmop \
--enable-sysvsem=shared \
--enable-sysvshm=shared \
--enable-sysvmsg=shared \
--enable-mbstring \
--enable-bcmath \
--with-libxml-dir=/opt/local \
--with-xsl=/opt/local \
--with-gettext=/opt/local \
--with-png-dir=/opt/local \
--with-jpeg-dir=/opt/local \
--enable-gd-native-ttf \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--with-mcrypt=/opt/local \
--with-iconv=/opt/local \
--with-t1lib=/opt/local \
--with-curl=/opt/local \
--with-snmp=shared
--enable-cli \
--enable-cgi \
--enable-fastcgi \
--enable-force-cgi-redirect \

3. hack
修改Makefile

(line 19) MH_BUNDLE_FLAGS=... 在 -L/usr/lib 前面添加 -L/opt/local/lib
(line 130) 在EXTRA_LIBS=... 最后添加 -lresolv

4. build
make && make install