Add mcrypt to Mac OS X (Snow Leopard 10.6, Lion 10.7, Mountain lion 10.8)

You can easily install the mcrypt extension to PHP5 on Mac OS X Server. Here’s how:

Download and install MacPorts from http://macports.org.

The following steps are performed in the Terminal:

Force MacPorts to update:
sudo port -v selfupdate

Now, install memcached:
sudo port install php5-mcrypt

Copy the newly created shared object for mcrypt into Mac OS X’s default PHP5 extension directory:
sudo cp /opt/local/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Next, you need to edit php.ini to add the extensions. Find the phrase Dynamic Extensions, and add:

extension=mcrypt.so

And finally, restart Apache:
sudo apachectl restart

To confirm installation, create a new PHP document called phpinfo.php with the following contents:
< ?php phpinfo(); ?>

Point your browser to the URL of that file. If all went well, you’ll see this block:

Screen-shot-2011-01-27-at-9.48.58-PM