Install mcrypt PHP extension on Mac OS X Lion

Important: This article was originally published in 2011, and I wouldn’t recommend you use mcrypt in your PHP project any more (reasons why). If you absolutely need it… then read on….

mcrypt php extension

If you have a need to install the mcrypt extension for PHP, for example if you need to use phpMyAdmin, Magento or Laravel, then these instructions are for you.

Thankfully, it is becoming simpler to install PHP extensions than with previous versions of OS X.


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.


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
tar zxvf autoconf-latest.tar.gz
cd autoconf-2.69
./configure; make
sudo make install


libmcrypt is the library that provides the encryption functions. We need to install this before building the PHP extension.

  • Open up
  • Download libmcrypt from sourceforge
  • Unpack the archive somewhere
  • cd libmcrypt
  • ./configure
  • make
  • sudo 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.

You should see output similar to the following:

Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
  • ./configure
  • make
  • sudo 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 =

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.

P.S. – Looking for a reliable hosting provider for your PHP projects? I recommend Clook:

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:

70 thoughts on “Install mcrypt PHP extension on Mac OS X Lion

  1. Kevin

    Nice. Very helpful. But this line in php.ini didn’t work:

    extension =

    Until I added this line earlier in the file:

    extension_dir = “/usr/lib/php/extensions/no-debug-non-zts-20090626/”

    Just in case anyone runs into that problem.

  2. Pingback: September 28 blog – Dan Spencer » Installing libmcrypt + php mcrypt on Mac OS X Lion

  3. Prasanna


    I already have PHP 5.3.6 that came with my mac. What should I do in order to install and enable mcrypt? Or you know to upgrade PHP to 5.3.8 completely?

    1. Glen Post author

      Hey Prasanna: PHP 5.3.6 does not contain the mcrypt extension, so you need to following the instructions in this post to enable it. Even though you have 5.3.6 installed, you still need to download the source code in order to compile the mcrypt extension correctly.

  4. Rohit Sangal

    Done with all the steps, but still no php mcrypt documentation and the same error(mcrypt extension is missing) continues….do help:(

  5. kgi111

    I have tried for some time using different site to get crypt to work on Lion 10.7.3 beta 2
    I use php 5.3.8
    I have the later Xcode version.
    No matter what I do I get
    /SourceCache/php-5.3.8/ext/mcrypt/mcrypt.c:282: error: ‘PHP_FE_END’ undeclared here (not in a function)

    I have tried to figure if there si som missing includes. But right now I am stuck

  6. Colin

    Thanks for the instructions, but I can’t get it to work. libmcrypt-2.5.8 builds fine, and php-5.3.6/ext/mcrypt builds fine. I even ran make test for the PHP build and all tests pass.

    I added the two lines into php.ini and tried to restart Apache (both from the command line, and from System Preferences / Sharing / Web Sharing) … no luck.

    Apache won’t start, and there isn’t anything useful in the logs. Running PHP from the command line seems fine, and I can see the mcrypt extension listed in phpinfo().

    Any suggestions? I’m on OS X 10.7.2, with Xcode 4.2.1 (4D502).

  7. Colin

    Further to my previous post, I can’t Apache to start at all now! Taking the mcrypt-related lines out of php.ini doesn’t help. Argh!

    1. Glen Post author

      Hey Colin,

      If you run the following command in your terminal, what output do you get?

      sudo apachectl restart ; tail -f /var/log/apache2/error_log

  8. Colin

    I checked the Apache logs. Nothing relevant.

    It turns out that Apache is restarting. I think it’s just taking a bit longer to start up now … and maybe System Prefs has a built in time-out to check if it was successful?

    In any event, if I start it from the command line, I can see the process in ps aux. If I start it from System Prefs, it doesn’t show it as started right away. The process is there though. If I close System Prefs and re-open it, Web Sharing is checked.

  9. Marvin Yoon

    Finally, I solved this problem using this article.
    But one thing to keep in mind is that don’t forget to copy “php.ini.default” in /etc directory to “php.ini” in the same directory. (There was only exist php.ini.default file, not exist php.ini file in /etc directory!!)

  10. Colin

    Back again, and after upgrading to 10.7.3, I get the same error as @kgi111:

    /Users/cmv/src/php-5.3.8/ext/mcrypt/mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)

    Any suggestions? A search recommends changing all occurrences of PHP_FE_END to {NULL, NULL, NULL} … but that just seems like a hack.

    1. Glen Post author

      Hey Colin,

      Yes, this error occurs with the PHP 5.3.8 source. I have no idea why. make still works fine with the 5.3.6 sources, and the resulting compiled extension should still work on 10.3.7 so I suggest using these rather than hacking 5.3.8.

  11. Nguyen Tran Viet

    On my other machine installing Xcode 4.3, when run ./configure to install libmcrypt-2.5.8, it produce the error:

    Applehouses-MacBook-Pro-7:libmcrypt-2.5.8 Applehouse$ ./configure
    checking build system type... i686-apple-darwin11.3.0
    checking host system type... i686-apple-darwin11.3.0
    checking target system type... i686-apple-darwin11.3.0
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for gawk... no
    checking for mawk... no
    checking for nawk... no
    checking for awk... awk
    checking whether make sets $(MAKE)... no
    checking whether to enable maintainer-specific portions of Makefiles... no
    checking whether make sets $(MAKE)... (cached) no
    checking for g++... no
    checking for c++... no
    checking for gpp... no
    checking for aCC... no
    checking for CC... no
    checking for cxx... no
    checking for cc++... no
    checking for cl... no
    checking for FCC... no
    checking for KCC... no
    checking for RCC... no
    checking for xlC_r... no
    checking for xlC... no
    checking for C++ compiler default output file name... configure: error: C++ compiler cannot create executables
    See `config.log' for more details.

    I’m not sure whether Xcode 4.3 is the reason. Please help me

    1. Glen Post author

      Hey Nguyen,

      Where do you have the developer tools installed on your other machine? I’ve heard that if you have spaces in the pathname, it may cause problems (for example, if devtools are installed under /Developer 4.3/ rather than just /Developer/).

  12. Nathan

    Thanks. If it weren’t for people like you how post step-by-step instructions on how to do things like this we would all be in the dark ages.

  13. GGavrilut

    Thank you,

    After a few hours of struggling with installing mcrypt, I succeeded thanks to your article.

  14. Paul

    When run ./configure to install libmcrypt-2.5.8, it produce the error:

    aag4server:libmcrypt sydchess$ ./configure
    checking build system type… i686-apple-darwin11.3.0
    checking host system type… i686-apple-darwin11.3.0
    checking target system type… i686-apple-darwin11.3.0
    checking for a BSD-compatible install… /usr/bin/install -c
    checking whether build environment is sane… yes
    checking for gawk… no
    checking for mawk… no
    checking for nawk… no
    checking for awk… awk
    checking whether make sets $(MAKE)… no
    checking whether to enable maintainer-specific portions of Makefiles… no
    checking whether make sets $(MAKE)… (cached) no
    checking for g++… no
    checking for c++… no
    checking for gpp… no
    checking for aCC… no
    checking for CC… no
    checking for cxx… no
    checking for cc++… no
    checking for cl… no
    checking for FCC… no
    checking for KCC… no
    checking for RCC… no
    checking for xlC_r… no
    checking for xlC… no
    checking for C++ compiler default output file name… configure: error: C++ compiler cannot create executables
    See `config.log’ for more details.
    aag4server:libmcrypt sydchess$ make
    -bash: make: command not found
    aag4server:libmcrypt sydchess$ sudo make install
    sudo: make: command not found

    Please help me!

  15. EC

    Thanks for this. Followed your directions from start to finish and everything went off without a hitch. One of the few (if not only) times that’s happened when I’ve followed someone’s blog post to solve a problem.

  16. Nam, Sang-gyu

    Great tutorial! Thank you for letting me know how to plug this module on Mac OS X Lion.
    Well, I use Mac OS X Lion 10.7.4, and the default PHP version is 5.3.10. I downloaded PHP source of ver. 5.3.10 instead of ver. 5.3.6, and there was no problem phpize-ing mcrypt. Also, I should have installed autoconf for phpize-ing. Those are the information I would give to you.
    Anyway, thank you for tutorial! 😀

  17. Pingback: Turn Mac OS X Lion Into a LAMP Web Server (Without MAMP) ⊆ David Xia

  18. Hero Jig

    Like Nan above, I ran into the same (I had to instal macports to get autoconfig) but I used PHP version 5.3.6 to build mcrypt. Hope that does not come back to bite me on 10.7.4. Anyway, all is well now so thx for the great headstart on this one!

    btw, I am new to lion servers and was wondering: can I just install MAMP pro on these boxes and be done with it? Seems like that would easier… but sure to break things, I’m sure…

  19. Stanislav Kirilov

    almost at the end, I get this message:
    Configuring for:
    PHP Api Version: 20090626
    Zend Module Api No: 20090626
    Zend Extension Api No: 220090626
    Cannot find autoconf. Please check your autoconf installation and the
    $PHP_AUTOCONF environment variable. Then, rerun this script.

    1. Glen Scott Post author

      Hi Stanislav,

      autoconf is part of the Command Line Tools package provided by Apple. Do you have it installed?

  20. Pingback: mac 10.8에서 mcrypt관련 php오류난 경우 « June

  21. R Burke

    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).

  22. Sergio

    Thanks a lot. I had spent so many time trying to instal mcrypt

    With this tutorial was easy and fast. Thanks again

  23. Ulises

    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:

  24. Tom Sam

    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.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.