If you have a need to install the mcrypt extension for PHP, for example if you need to use phpMyAdmin or Magento, then these instructions are for you.
Thankfully, it is becoming simpler to install PHP extensions than with previous versions of OS X.
Xcode
The Xcode package installs the necessary tools which are needed during the PHP extension compilation process. Make sure you have at least Xcode v4.1 installed; the install package ("Install Xcode") is available in your "Applications" folder.
If you are running Xcode 4.3 or above, please check you have the command line tools installed before proceeding.
Autoconf
The most recent version of Xcode does not include autoconf which is a pre-requisite. To check that you have it, run the following command in your Terminal:
autoconf --version
If you see output similar to the following, then it means you have it installed -- skip to the libmcrypt section.
autoconf (GNU Autoconf) 2.61
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License
There is NO WARRANTY, to the extent permitted by law.
Written by David J. MacKenzie and Akim Demaille.
If you get a command not found error, then you will need to perform the following to install autoconf:
cd /tmp
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar zxvf autoconf-latest.tar.gz
cd autoconf-2.69
./configure; make
sudo make install
libmcrypt
libmcrypt is the library that provides the encryption functions. We need to install this before building the PHP extension.
- Open up Terminal.app
- Download libmcrypt from sourceforge
- Unpack the archive somewhere
cd libmcrypt./configuremakesudo make install
PHP Extension
Once we have libmcrypt installed, we can build the PHP extension. One important point: even though PHP 5.3.8 is now the default since Mac OS X 10.7.3, attempting to compile with these sources results in the following error:
php-5.3.8/ext/mcrypt/mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)
Therefore, we need to use PHP 5.3.6 sources which compiles fine and still works with 10.7.3.
- Download PHP 5.3.6 source
- Unpack the archive and
cd php-5.3.6/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.




Thank you this was brilliant advice, simply explained and worked a treat.
Thanks again
Ta, mate! Got phpMyAdmin up and running with this!
Brilliant. Thanks, mate!
will this work if I have PHP5.4.8 ?
Thanks so much. When the Apple OS-X upgrade destroyed my development environment, you helped me get it back.
Thanks for these instructions! I've used them 2x now: one on initial set-up, the other after a Mountain Lion upgrade (which blew everything else away).
Thanks a lot. I had spent so many time trying to instal mcrypt
With this tutorial was easy and fast. Thanks again
Thanks a lot.
why apple not do that?
Using Lion 10.8
After trying to ./configure while installing libmcrypt I got the following issue:
*** Could not run libmcrypt test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means LIBMCRYPT was incorrectly installed
*** or that you have moved LIBMCRYPT since it was installed. In the latter case, you
*** may want to edit the libmcrypt-config script: no
configure: error: *** libmcrypt was not found
Do you have any solution or suggestion to fix this issue:
Hi, i am getting the following error
correct 'make' to '_make' [nyae]?
any ideas thanks
Thanks for making the internets better. Followed several. Yours nailed it.
This was a great and very thorough guide, great that you provided links to all the things whiich needed to be downloaded. I only wish that xcode 4 was available somewhere publicly for download, not just for Apple developers. I wanted to download it from the app store but they require a credit card and I just didn't want to do that.