First mcrypt on Leopard, and now we ready for the winter cat. Additionally, special thanks goes out in advance to commenter Yvan Barthelemy (a.k.a. ybart) for cluing me in here. The procedure is almost exactly like the previous…almost. So pay attention.
The following instructions cater to those who a) are developing on OS X Snow Leopard 10.6.1, b) need the capabilities provided by mcrypt during their PHP development, and c) do not want to completely recompile PHP to get there. You’ll get mcrypt loading dynamically for use in PHP with this method.
First, you are going to need a few things…
1) libmcrypt-2.5.8, which you can pick up here; NOTE: make sure to get libmcrypt and not mcrypt.
2) PHP 5.3.0 source, which you grab here; ADDITIONAL NOTE: You may have already updated your OS X beyond 10.6.1, and PHP may have been updated along with it. In this case, use phpinfo() to check your version of PHP, and then download the PHP source for that version. Thanks to commenter Blair for suggesting this note;
3) Xcode 3.2 tools, which you can pick up here (Apple Developer Connection membership required).
Next, create a directory at root called ‘SourceCache’ and dump the files from #1 and #2 in there and unwrap.
Move to the libmcrypt-2.5.8 directory, and punch in this…
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking
sudo make install
libmcrypt is ready – now for the PHP extension…
Move back to /SourceCache, then down to php-5.3.0/ext/mcrypt – type…
/usr/bin/phpize (phpize should be in /usr/bin – if not go find it and change the command as appropriate)
Then configure as follows…
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Developer/SDKs/MacOSX10.6.sdk/usr/bin/php-config
make -j6 then
sudo make install
Make sure you have php.ini in the /etc directory (it will probably be php.ini.default to start, particularly if you’ve just done the Snow Leopard upgrade, so rename it). Ensure that
enable_dl = On but do not remove the
; from in front of
;extension_dir = "./". Add one line to the .ini file in the Dynamic Extensions section…
Restart Apache – you should be all set (again), according to phpinfo():
BIG NOTE: As the substantive content of this guide has aged a number of new releases have come out, including but not limited to patches for Snow Leopard. As a result, PHP versions have changed, XCode has been updated, and more. If you come across quirks during your attempts to get mcrypt working, please read the comments before detailing your problem, as many of those issues have been solved. Finally, thanks go out to all of the folks who have contributed – it is greatly appreciated by all!