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.
- 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
./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.
Thanks, this worked & saved a lot of time.
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.
thanks a lot every times i try to install phpmyadmin on my localhost, i’m still have the same error now it’s finish.
you are simple AWESOME. been looking around for hours, thanks alot!
thanks! you are a great man! It works perfectly!
Excellent post! Super clear instructions. Was a piece of cake loading mcrypt with this guide.
Excellent! Thanks a lot for this info. It now works!
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
Thanks for the post! really saved me time!
Thank you so much! A lifesaver!
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.
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!!
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?
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?
GD is installed without reference to freetype.
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.
Thanks for your directions. Works perfectly.
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.
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.
Thank you so much. I will read more carefully next time.
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?
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.
great walk through. I altered the ./config options a bit but other than that mycrypt is installed and playing nicely with roundcube.
thanks man
Thanks, Glen, this was a huge help and worked perfectly!
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
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