Install mcrypt PHP extension on OS X Snow Leopard

Lock away the evil...

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-shared
  • make
  • sudo make install

PHP Extension

Once we have libmcrypt installed, we can build the PHP extension.

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

mcrypt php extension

Comments

  1. Anna says:

    Thanks, this worked & saved a lot of time.

  2. David says:

    Thank you for this helpful tip.

    Now if only your posting would work itself to the top of Google's search results, you'd be helping a lot of frustrated Mac users.

  3. lazantsy says:

    thanks a lot every times i try to install phpmyadmin on my localhost, i'm still have the same error now it's finish.

  4. Taha Hesham says:

    you are simple AWESOME. been looking around for hours, thanks alot!

  5. giulio says:

    thanks! you are a great man! It works perfectly!

  6. Tobias K. says:

    Excellent post! Super clear instructions. Was a piece of cake loading mcrypt with this guide.

  7. Peter says:

    Excellent! Thanks a lot for this info. It now works!

  8. Thanks, helped a lot.

    For anyone having compile issues it may be that, like me, you are on a 32 bit Mac, in which case change

    export CFLAGS="-arch x86_64"

    for

    export CFLAGS="-arch i386"

    And finally, the link to the latest PHP version has changed, the following will work.

    http://www.php.net/get/php-5.3.6.tar.gz/from/a/mirror

  9. sbditto85 says:

    Thanks for the post! really saved me time!

  10. Chip Kreis says:

    Thank you so much! A lifesaver!

  11. David Simmer says:

    This was perfectly helpful. Thank you.

    FYI, trying to build this with the latest PHP package (5.3.8 at the moment) failed. 5.3.3 is no longer available on php.net, but the 5.3.4 package installed cleanly.

  12. Dave says:

    Similar to what David said. Tried with 5.3.8 and it failed. 5.3.3 is still there to download (it's below a more recent 5.2.x build) but I got 5.3.4 since that matches what my Snow Leopard shipped with. It worked!

    Thanks!!

  13. g.mays says:

    I couldn't find my Leopard install disk, so I downloaded Xcode from this page:

    http://developer.apple.com/devcenter/mac/index.action

    Then clicked on:

    Xcode 3.2.6 and iOS SDK 4.3Mar 24, 2011
    (~4gb download)

    Installed mcrypt ok using your libmcrypt and php links

    Now I need freetype support for GD. Any ideas?

  14. Glen says:

    I don't have Snow Leopard available to test Freetype, unfortunately. It actually comes pre-installed with OS X Lion: when you view the phpinfo details you can see the following:

    FreeType Support enabled
    FreeType Linkage with freetype
    FreeType Version 2.4.4

    What do you see with Snow Leopard?

  15. g.mays says:

    GD is installed without reference to freetype.

  16. sean says:

    thanks very much... your instructions were by far the simplest I have seen. There was no need to build the whole of php from source as many people say.

  17. Alex says:

    Thanks for your directions. Works perfectly.

  18. lianne says:

    Help me please, going crazy. After phpize and ./configure, I ran make and got this
    /bin/sh /Users/macbase/SourceCache/php-5.3.10/ext/mcrypt/libtool --mode=compile cc -I. -I/Users/macbase/SourceCache/php-5.3.10/ext/mcrypt -DPHP_ATOM_INC -I/Users/macbase/SourceCache/php-5.3.10/ext/mcrypt/include -I/Users/macbase/SourceCache/php-5.3.10/ext/mcrypt/main -I/Users/macbase/SourceCache/php-5.3.10/ext/mcrypt -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /Users/macbase/SourceCache/php-5.3.10/ext/mcrypt/mcrypt.c -o mcrypt.lo
    mkdir .libs
    cc -I. -I/Users/macbase/SourceCache/php-5.3.10/ext/mcrypt -DPHP_ATOM_INC -I/Users/macbase/SourceCache/php-5.3.10/ext/mcrypt/include -I/Users/macbase/SourceCache/php-5.3.10/ext/mcrypt/main -I/Users/macbase/SourceCache/php-5.3.10/ext/mcrypt -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /Users/macbase/SourceCache/php-5.3.10/ext/mcrypt/mcrypt.c -fno-common -DPIC -o .libs/mcrypt.o
    /Users/macbase/SourceCache/php-5.3.10/ext/mcrypt/mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)
    make: *** [mcrypt.lo] Error 1

    and sudo make install won't work either. Not even sure where to look for the answer.

  19. Glen says:

    You are using a version of the PHP source code that will not work (5.3.10). As per my instructions, you will need to use 5.3.4 to compile the mcrypt extension.

  20. lianne says:

    Thank you so much. I will read more carefully next time.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>