Rebuilding PHP extensions to work with Mac OS X Mavericks server and PHP 5.4

Because Mavericks server uses PHP 5.4, any extensions you may have compiled for previous versions of Mac OS X (such as memcache, apc, mcrypt) need to be recompiled and reinstalled.

This post assumes you used MacPorts to compile and install the PHP extensions in question. Here’s how to accomplish the task:

Force MacPorts to update from the terminal:

sudo port -v selfupdate

Next, determine which ports depend on the php5 port:

sudo port dependents php5

After visually confirming you want to get rid of them all, issue this command to uninstall the old versions of those ports:

sudo port uninstall --follow-dependents php5

Do the same for memcached (if you’ve installed it):

sudo port uninstall memcached

Now unload it:

sudo port unload memcached

Compiling the new PHP  5.4 version

Now, we need PHP 5.4 in order to build our extensions. So, let’s install the PHP 5.4 port:

sudo port install php54

Back up your existing /etc/php.ini file if you have one:

sudo cp /etc/php.ini /etc/php.ini.orig

Copy the php.ini file from the new port to your /etc/ directory. Choose the version (development or production) that suits your requirements:

cd /opt/local/etc/php54
sudo cp php.ini-production /etc/php.ini

Duplicate any modifications you made in your original php.ini.orig file in your new /etc/php.ini file.

Compiling new versions of PHP extensions

Now, use MacPorts to download and recompile your PHP extensions: