Archive for the 'Technokracy' Category

Fixing PHP 5.3.0 Build Problems on Snow Leopard

Building PHP from source on 10.6 produced a new problem I’ve not seen before. After successfully configuring and a few minutes of building, a link error stops the show, with the end part looking like:

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
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1
Error: Status 1 encountered during processing.

Some searching found MacPorts users were seeing the same problem, and the culprit was lresolv.

Simply adding a configure environment variable before the actual configure command created a Makefile which worked:

LIBS=-lresolv ./configure --with-apxs2 --with-gd (etc.)

Building PHP with MacPorts Apache2 & MySQL

In the past I’ve always installed Apache2 via MacPorts, MySQL from source or binary, and built PHP from source. While putting this all together on Snow Leopard, I decided to install MySQL from MacPorts as well:

sudo port -v install apache2 mysql5-server

After everything was built and installed, I then installed the dependencies I needed for PHP 5.3 from MacPorts (openssl, mcrypt, libxml, etc.). My full configure command is:

./configure \
--prefix=/usr/local \
--with-apxs2=/opt/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/etc/php5 \
--disable-cgi \
--enable-bcmath \
--with-gd \
--with-curl \
--enable-exif \
--enable-calendar \
--enable-mbstring \
--with-mysql=/usr/local/mysql \
--with-mysqli \
--with-pdo-mysql=/usr/local/mysql \
--with-zlib-dir=/opt/local \
--with-openssl=/opt/local \
--with-mcrypt=/opt/local \
--with-mhash=/opt/local \
--with-freetype-dir=/opt/local \
--with-jpeg-dir=/opt/local \
--with-png-dir=/opt/local \
--with-libxml-dir=/opt/local \
--with-xsl=/opt/local \
--with-gettext=/opt/local \
--with-bz2 \
--with-iconv=/opt/local

Notice –with-mysql=/usr/local/mysql? No matter how many paths I tried I could not get PHP to configure with MySQL. Apparently the MacPort changes the layout for some reason. My solution (inspired by a 2007 discussion on the MacPorts mailing list) involved making a few symlinks:

sudo mkdir -p /usr/local/mysql
cd /usr/local/mysql
sudo ln -s /opt/local/include/mysql5 include
sudo ln -s /opt/local/lib/mysql5 lib
sudo mkdir bin
cd bin
sudo ln -s /opt/local/bin/mysql_config5 mysql_config

Once the symlinks were in place, PHP configured without error.