Recompiling PHP5 on Snow Leopard with MySQLi support, and other things


[update 04.05.2010. If you got the OS X 10.6.3 update you may find yourself reading this again since it overwrites your php library. Yes, we found out the hard way. Backup your library first. ]

We just got a new workstation in the office. After getting it out of the box we were happy to realize that it already comes with a much better configuration for php 5.3 than the old 5.2 of OS X Leopard. Leopard only came with a very few and basic configuration and libraries, that were only fit to new web designer. Apparently they noticed this at Apple and this new version comes with a much better library set.

In general we have more than once person developing a site. So we use mysql databases that are hosted in a server that anyone can access, that way when someone makes a change to the databases it is immediately propagated to all developers, since we use something similar to a “networked drive.”

However, MySQL is still not included, but the folks at mysql have created a dmg that allows you to easily install mysql into your computer. You just need to download it, double click, and follow the prompt. The problem is that php comes with a strange version of mysqli. We were all exited and ready to go when:

Warning: mysqli::mysqli() [mysqli.mysqli] OK packet 6 bytes shorter than expected in /path/to/file on line…

mysqlidev won't let you connect to remote servers

This happens because the mysqli API library that php is using is the one that comes by default, not the one from the mysql version we just installed. Shoots, we need to recompile, and since we are at it, we will also recomplile with the new version of jpeglib.

Now it makes sense just to grab the configure options shown by phpinfo, but for some reason it references some locations that do not exists for jpeglib and libpng. So we will need to compile those too. Also make sure to remove your dir path from pcre otherwise it will also trow you and error.

Okay, let’s do this. First we download our source for PHP, LibJPEG, LibPNG

Lets compile libjpeg first: Once you have uncompressed the source, just go into the directory and type in the following

CFLAGS="-arch x86_64 -Os -pipe -m64" CXXFLAGS="-arch x86_64 -Os -pipe -m64" LDFLAGS="-arch x86_64 -Os -pipe -m64" ./configure --enable-shared

That should finish without problems, now go to your libpng folder and type the following

./configure --enable-shared

Again, it should finish without problems. Do the same for libPNG, and

Now, it would make sense to compile php now, but there are some know bugs in php when compiling on a mac so lets get those corrected first, before we continue.

Fist you will need to modify the file ext/gd/libgd/gd_png.c, so open it with your favorite text editor and look for the following string:



if (!png_check_sig (sig, 8)) { /* bad signature */


and replace it for this other line:



if (!png_sig_cmp (sig, 0, 8) == 0) { /* bad signature */


Now, using your favorite text editor go to the following file within your php source code ext/libiconv/libiconv.c
and look for



#define iconv libiconv


and replace the libconv of the second line for just iconv

Okay, now we are ready to compile php, so go to the the root of your php source code and type in (copy & paste) the following

CGLAGS="-arch x86_64 -Os -pipe -m64" CXXFLAGS="-arch x86_64 -Os -pipe -m64" LDFLAGS="-arch x86_64 -Os -pipe -m64" ./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=/user/local' '--with-png-dir=/usr/local' '--enable-gd-native-ttf' '--with-ldap=/usr' '--with-ldap-sasl=/usr' '--enable-mbstring' '--enable-mbregex' '--with-mysql=mysqlnd' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/var/mysql/mysql.sock' '--with-iodbc=/usr' '--enable-shmop' '--with-snmp=/usr' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-xmlrpc' '--with-iconv-dir=/usr' '--with-xsl=/usr' '--with-pcre-regex'

Life is good

Now, go and grab yourself a cup of coffee, this is going to take a while. After that you should be able to connect to any remote mysql server that you have access to.

If you share your workstation with someone else, then it may be a good idea to secure your mysql installation.

Now, in order to make your .htaccess files to work, you need to change your apache user settings. For that you need to go to /etc/apache2/users/USERNAME.conf and make sure it reads something like this
Options Indexes -MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

You will also need to change the second AllowOverride that you find in your /etc/apache2/httpd.conf

Well, that should do it. So good luck and let us know if you run into any problem.

Leave a Reply

Required fields are marked *.

* Copy This Password *

* Type Or Paste Password Here *