PHP 5.4 Installation on Mountain Lion

I just installed Mountain Lion, and of course I've had to set up Xcode Command Line Tools, reinstall Git, and do other things to get up and running again for programming. Naturally, PHP was pushed back to 5.3 from 5.4 that I previously had installed when my MacBook Pro was running Lion. I ran through the process downloading PHP 5.4, unzipping it (tar xf php5.4), configuring it (./configure with and without options), making it (make), running the make test (make test), and installing the make (sudo make install). When I ran configuration with options it did not allow me to make and when I ran without configuration options it failed to pass make test a few times (when this occurred I sent the information to Zend). When it did pass make test though, it said that it installed successfully, but when I would check the version (php -v) it still comes up with PHP 5.3. I've done this almost nine times with restarts and re-downloading the package every time; no sauce. Does anyone have any ideas what could possibly be going wrong? Any help on this issue would be greatly appreciated.


I strongly suggest you use the package installer or use a full stack of configuration options when compiling, including the --prefix option so you know where the binary gets installed to.

I can only guess PHP 5.4 installed itself into /usr/local/bin or somewhere else and didn't just overwrite the default binary in /usr/bin. And you seem to have not modified your PATH variable to prioritise the bin directory of /usr/local with e.g. PATH="/usr/local/bin:$PATH" in your .bash_profile. So, it's expected running php will still use /usr/bin/php and not /usr/local/bin/php.

Alternatively, you could just symlink the new php binary to /usr/bin/php, (delete or rename the default binary before that):

ln -s /usr/local/bin/php /usr/bin/php

I've installed MAMP and everything works fine.


Have you tried installing it via Homebrew?

Also just found a blog post (you have to scroll down a bit to the Homebrew section) which is saying that the problem with compiling PHP might be because ML doesn't come with X11, but there's a workaround.

Actually, here's the relevant bit from the blog post:

Apple removed support for X11 in Mountain Lion. This means that anything that was linking to a library that was supplied by X11 would now complain and die. This meant our custom compiled version of PHP at work. dylibs were missing which prevented PHP from running and header files could not be found which prevented an update to PHP from compiling.

The Homebrew folks saw it coming a while back. There are pull requests and changes in branches that deal with this issue. However the best I can tell not all of that has made it in to master and its still not ready to go.

There is a work around, and it relies on installing XQuartz to provide the required X11 libraries. This may not be required for everyone, but for those of us that run specific versions of software it means a headache. In our case, for PHP, it meant that libraries required for font and image handling were missing. And these are just the errors that came up first. I’m not sure how many other things that X11 provided were waiting to error out should we have tried to link in the parts as we found the errors.

First, download and install XQuartz. After doing that symlink it in to where Homebrew expects X11 to be. We had folder there, presumably left over from the upgrade.

$ cd /usr
$ mv X11 X11.bak
$ ln -s /opt/X11 X11

Now, since this was an OS upgrade all of the config and ini files have been renamed and replaced. This means that the Apache conf and PHP ini files needed replacing. Fortunately for us we had a custom Homebrew Formula that handled this portion of the environment for us. So we just had to uninstall and reinstall that Formula to re-configure Apache and PHP how we had it. Your setup will of course be different.