Thursday, February 3, 2011

Installing MySQL 5.5.8, Apache 2.2.17, and PHP 5.3.5 on Snow Leopard

This was way more of a struggle than I was looking for, especially compiling PHP, so I thought I'd share what worked for me in case somebody else runs into the same problems. Initially, I just hoped to update PHP 5.2.9 to 5.3.5, but I immediately ran into issues so I just updated everything. This was all for an effort to get an instance of SugarCRM 6.1.1 running and it would have been easier to just grab their FastStack installers (, but I have other PHP/Apache projects I need to support.

Updating to MySQL 5.5.8

Super easy as I had MySQL 5.0.45 installed previously. Just went to and grabbed the tar.gz file. After mysqldump'ing my old databases I simply ran these steps:

sudo mv ~/Downloads/mysql-5.5.8-osx10.6-x86_64.tar.gz /usr/local
cd /usr/local/
sudo tar -xvf mysql-5.5.8-osx10.6-x86_64.tar.gz
sudo ln -s /usr/local/mysql-5.5.8-osx10.6-x86_64 mysql
cd mysql
sudo chown -R _mysql .
sudo chgrp -R _mysql .
scripts/mysql_install_db --user=mysql
sudo chown -R root .
sudo chown -R _mysql data
sudo /usr/local/mysql/bin/mysqld_safe --user=mysql

I then reimported my data by opening a mysql prompt, creating the database, exiting, and then reimporting my data with mysql -u root -p db name < mysqldump file

Installing Apache 2.2.17

I was upgrading from Apache 2.2.5, but I don't use a lot of compiled modules so this was also straightforward. First grab the latest apache at Then do:

sudo su
mv ~/httpd-2.2.17.tar.gz /usr/local/src
cd /usr/local/src
tar -xvf httpd-2.2.17.tar.gz
cd httpd-2.2.17
./configure --prefix=/usr/local/apache2
sudo make install

This puts everything in /usr/local/apache2.

Installing PHP 5.3.5

This was the biggy and the reason for this post. I use a number of PHP modules: apxs, mysql, zlib, curl, mbstring, soap, openssl, and iconv. iconv was the initial pain.

Updating iconv

First, get the latest PHP release I originally was trying to configure with this (note this is stored in config.nice so I tend to edit that directly rather than typing these long strings on the command line):

./configure' \
'--with-apxs2=/usr/local/apache2/bin/apxs' \
'--with-mysql=/usr/local/mysql' \
'--enable-mbstring' \
'--with-zlib' \
'--with-iconv=/sw' \
'--with-curl=/sw' \

This immediately spit out:

checking for iconv support... yes
checking for libiconv in -liconv... no
checking for iconv in -liconv... no
configure: error: Please reinstall the iconv library.

This config definitely used to work (I have a PHP 5.2.9 install to prove it), but one of the OS updates must have changed something somewhere. I'm pretty sure I previously installed iconv with fink, but I've sort of given up on using it all the time in favor of compiling things myself. I got make to run through by changing '--with-iconv=/sw' to use '--with-iconv=/usr', but then immediately failed with this:

php5.bundle libs/
Undefined symbols:
"_libiconv_open", referenced from:
__php_iconv_strlen in iconv.o
_php_iconv_string in iconv.o

I continued to hunt and peck for awhile and did a bunch of mindless trial and error. Here's what eventually worked for getting through iconv (I had more problems, which I fixed below):

  1. Download a new iconv at After getting the software and extracting it I ran:
    ./configure --prefix=/usr/local
    make install
  2. I had to manually edit one of PHP's files, "php-5.3.5/ext/iconv/iconv.c" changing
    #if defined(HAVE_LIBICONV) &amp;&amp; defined(ICONV_ALIASED_LIBICONV)
    #define iconv libiconv
    #if defined(HAVE_LIBICONV) &amp;&amp; defined(ICONV_ALIASED_LIBICONV)
    #define iconv iconv
  3. I then modified the configure to contain '--with-iconv-dir=/usr/local'

This got the iconv portion working, but I immediately ran into library issues with mysql.

Fixing MySQL

Here was my initial error:

libs/libphp5.bundle libs/
Undefined symbols:
"_res_9_dn_expand", referenced from:
_php_parserr in dns.o
_php_parserr in dns.o

This was a linker issue that was solved by making a few additions to the configure command in config.nice:

CFLAGS='-arch x86_64' \
CXXFLAGS='-arch x86_64' \
LIBS='-lresolv' \
'./configure' \
'--with-apxs2=/usr/local/apache2/bin/apxs' \
'--with-mysql=/usr/local/mysql' \
'--with-iconv=/usr/local' \
'--enable-mbstring' \
'--with-zlib' \
'--with-curl=/sw' \

Immediately ran into another error, which was, thankfully, the last hurdle.

libs/libphp5.bundle libs/
Generating phar.phar
dyld: Library not loaded: libmysqlclient.16.dylib
Referenced from: /usr/local/src/php-5.3.5/sapi/cli/php
Reason: image not found
make: *** [ext/phar/phar.phar] Trace/BPT trap

I was able to fix the "make" step by adding "/usr/local/mysql" to my DYDL_LIBRARY_PATH, but "make install" then failed:

Installing PEAR environment: /usr/local/lib/php/
dyld: Library not loaded: libmysqlclient.16.dylib
Referenced from: /usr/local/src/php-5.3.5/sapi/cli/php
Reason: image not found
make[1]: *** [install-pear-installer] Trace/BPT trap
make: *** [install-pear] Error 2

Much more unsuccessful hunting and pecking insued, followed by figuring out the path of mysql shared library was missing. Here was the initial otool output:

$ otool -DX /usr/local/mysql/lib/libmysqlclient.16.dylib

Which I fixed by running:

$ sudo install_name_tool -id /usr/local/mysql/lib/libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.dylib

otool then spit out the full path:

$ otool -DX /usr/local/mysql/lib/libmysqlclient.16.dylib

This was the ticket for me. No doubt I glossed over all the root causes of these problems. Don't forget to run make clean. Whew!

1 comment: