Installing PHP 5.2.10 on Mac OS X 10.6 Snow Leopard
Apple deserves serious props for bringing the installed version of PHP up to 5.3 on Snow Leopard, but some projects *cough CakePHP* can’t yet handle the goodness.
Sure, you could virtualize Ubuntu running whatever setup you desired, but if you already had a local setup on Leopard, it might make more sense to downgrade to PHP 5.2 and get back to work.
There’s a lot of confusion and little documentation online about how this is done, so here is the easiest way to make it happen:
- Install the “Snow Leopard” version of MacPorts from: http://www.macports.org/install.php
- In Terminal, run:
> sudo port -v selfupdate > sudo port -f uninstall installed > sudo port install php52 +mysql5 +sqlite > sudo cp /opt/local/etc/php5/php.ini-dist /opt/local/etc/php5/php.ini
- Open /etc/apache2/httpd.conf and change line 114 from:
LoadModule php5_module libexec/apache2/libphp5.so
to:LoadModule php5_module /opt/local/apache2/modules/libphp5.so
- Open /opt/local/etc/php5/php.ini and change line 761 from:
mysql.default_socket =
to:mysql.default_socket = /var/mysql/mysql.sock
- Use the Sharing pane of System Preferences to stop and start Web Sharing
Purists will argue that you now have lots of extra software installed on your system, which is true, but let’s be real: these 5 steps are the fastest way to get back to being productive.
Update (March 30, 2010): If you are seeing weird errors with curl and SSL/https connections, it’s because the version of libcurl that this install is NOT compatible. Here’s how to fix it:
> sudo mv /opt/local/lib/libcurl.4.dylib /opt/local/lib/libcurl.4.dylib.old > sudo ln -s /usr/lib/libcurl.4.dylib /opt/local/lib/libcurl.4.dylib > sudo mv /opt/local/lib/libcurl.dylib /opt/local/lib/libcurl.dylib.old > sudo ln -s /usr/lib/libcurl.dylib /opt/local/lib/libcurl.dylib
Enjoy!