PHP 5.3.0 on Mac OS 10.6 (Snow Leopard)

Fabien Potencier

November 05, 2009

Recently, I started to use PHP 5.3.0 extensively, thanks to the move of Symfony 2 to PHP 5.3. To do my work, I need to have several different versions of PHP at hand, with different configurations, and so I always compile my own PHP and Apache binaries on my Mac. But as Snow Leopard comes bundled with PHP 5.3.0, I started some PHP 5.3.0 experiments with the bundle version and everything went well for a couple of days.

Now that I use PHP 5.3.0 more and more, I decided it was time to compile my own version. As it turns out, compiling PHP 5.3.0 on Snow Leopard is a bit involving. As I loose some time before finding the right solution, here is what I did step by step (I have just followed the tips referenced in the ticket opened for the issue on, so all credits go to them).

First, I ran the configure script with my usual options and added --with-iconv-dir=/usr at the end:

$ ./configure ... --with-iconv-dir=/usr

If you have upgraded your Mac to Snow Leopard, you should know that everything must now be compiled for 64 bits. It means that you might need to recompile extra libraries needed by PHP like libjpeg or libpng, or even re-install a 64 bits version of MySQL.

I then patched the iconv.c file the same way Apple did for their own version:

--- php-5.3.0/ext/iconv/iconv.c 2009-03-16 22:31:04.000000000 -0700
+++ php/ext/iconv/iconv.c   2009-07-15 14:40:09.000000000 -0700
@@ -51,9 +51,6 @@
 #include <gnu/libc-version.h>
-#undef iconv
 #include "ext/standard/php_smart_str.h"
 #include "ext/standard/base64.h"
@@ -182,9 +179,6 @@
 /* }}} */
-#define iconv libiconv
 /* {{{ typedef enum php_iconv_enc_scheme_t */
 typedef enum _php_iconv_enc_scheme_t {

To apply the patch, save the above text in a file (patch) and from the root source of PHP, type the following command:

$ patch -p1 < patch

Then, add -lresolv to the EXTRA_LIBS variable:

$ export EXTRA_LIBS=-lresolv 

Eventually, run the usual make commands

$ make
$ make install


gravatar Scott MacVicar  — November 05, 2009 17:02   #1
The DNS issue is fixed in 5.3.1, the iconv issue should be fixed in 5.3.2. Just taking some time to test my patches on all platforms.
gravatar Ryan Parman  — November 05, 2009 20:53   #2
I wrote up an alternate approach a few months ago using MacPorts, that works beautifully for me on Snow Leopard.
gravatar PJ  — November 06, 2009 05:00   #3
why not just use macports and be done?

$ sudo port install php5

its even 64bit in Snow Leopard
gravatar Philip Olson  — November 07, 2009 00:27   #4
Regarding not macports, because some people compile PHP with different options, or want to compile snapshots, alphas, betas, release candidates, ...
gravatar Eriksen Costa  — November 09, 2009 05:14   #5

Could you provide more details in the way you handle the different versions of PHP?

I currently use --program-suffix=VERSION in configure to manage different versions but I am thinking in use a --prefix to separate every PHP version in a self-contained directory.

Then, I would just symlink things like the Apache module to a PHP dir and update the system path to a specific version when convenient.

You don't need to edit the Makefile, just export EXTRA_LIBS in your shell env:
$ export EXTRA_LIBS=-lresolv

gravatar Fabien  — November 09, 2009 07:11   #6
@Eriksen: As you suggest, I use the --prefix when configuring both Apache and PHP. For each version of PHP I compile, I also compile a dedicated Apache. And the configuration is the same for all my Apache. Running two different Apache is also possible by changing the bound IP. Nothing fancy, but it works perfectly.
gravatar Eriksen  — November 10, 2009 14:28   #7

Compiling a dedicated Apache seems more practical than just one.

gravatar Kolea  — November 23, 2009 13:08   #8
Fabien, how do you run different versions of PHP under the same apache installation?
Thank you.
gravatar Kolea  — November 23, 2009 13:09   #9
Sorry, just noticed the answer :D
gravatar MySchizoBuddy  — December 13, 2009 20:12   #10
Will you be testing Symfony2 on Nginx as well.