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

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:
TwitterFacebookLinkedIn

26 thoughts on “Install mcrypt PHP extension on OS X Snow Leopard

  1. David

    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.

    Reply
  2. David Simmer

    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.

    Reply
  3. Dave

    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!!

    Reply
    1. Glen Post author

      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?

      Reply
  4. sean

    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.

    Reply
  5. lianne

    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.

    Reply
    1. Glen Post author

      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.

      Reply
  6. Arif

    Hey Glen, I didn’t expect to find your site when searching for mcrypt! Useful stuff you have on here. Thanks mate! How’s the little one?

    Reply
  7. Attila Fülöp

    Thanks Glen. I also ran into lianne’s problem while trying to build the extension from php 5.3.8 sources on OSX 10.6.

    I have php 5.3.8 so I thought that’ll be the best. As Richard Smith recommended I used 5.3.6 and that compiled nicely.

    Reply
  8. cowan

    great walk through. I altered the ./config options a bit but other than that mycrypt is installed and playing nicely with roundcube.

    thanks man

    Reply
  9. Maliheh

    Thanks for this guide. I followed the instruction, mcrypt is now active but the supported algorithm and mode is empty. can you help me with this?
    Supported ciphers none
    Supported modes none

    Reply
  10. lvivnative

    Please help: when I try to run the ./configure command, I get a message “no such directory” I’m on 10.6.8. I was able to install the libmcrypt-2.5.8, but can not configure PHP. Thank you

    Reply

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.