Please note: The following instructions apply to Mac OS X 10.6 (Snow Leopard). I have an updated guide for how to install mcrypt on 10.7 (Lion).
mcrypt is a useful extension to PHP if you would like to support a wide range of encryption algorithms within your code.
This guide explains how you can enable install mcrypt, along with the PHP extension, on Mac OS X 10.6.
Xcode
The Xcode package installs the necessary versions of tools like autoconf which is needed during the PHP extension compilation process. Make sure you have at least Xcode v3.2 installed; the install package is available on the Snow Leopard install DVD under the “Optional Installs†folder.
libmcrypt
libmcrypt is the library that provides the encryption functions. We need to install this before building the PHP extension.
- Open up Terminal.app
export CFLAGS="-arch x86_64"- Download libmcrypt from sourceforge
- Unpack the archive somewhere
cd libmcrypt./configure --disable-sharedmakesudo make install
PHP Extension
Once we have libmcrypt installed, we can build the PHP extension.
- Download PHP 5.3.4 source (tar gz format)
- Unpack the archive and
cd php-5.3.4/ext/mcrypt/ - phpize
You should see output similar to the following:
Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626
./configuremakesudo make install
On successful install, you will see the following message:
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20090626/
To enable the module, include the following line in your /etc/php.ini file:
extension = mcrypt.so
Finally, restart your Apache server:
sudo apachectl restart
And that's it: you should now be able to utilise the functions, as detailed in the PHP mcrypt documentation.

