Mac OS X Snow Leopard Missing Mcrypt for PHP

Trying to setup a WordPress dev sandbox on my MB Pro and use phpMyAdmin for database setup and maintenance. The first thing that phpMyAdmin complained about was that libmcrypt was missing. After a few web searches, found this helpful info from Michael Gracie.

  1. First, you’re 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; and

    3. Xcode 3.2 tools, which you can pick up here (Apple Developer Connection membership required).

  2. Next, create a directory called ‘SourceCache’ and move the libmcrypt-2.5.8 and php-5.3.x directories in there and unwrap.

  3. Open up a Terminal, cd SourceCache/libmcrypt-2.5.8, 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

and then… make -j6 and finally… sudo make install

libmcrypt is ready – now for the PHP extension…

  1. cd SourceCache/php-5.3.0/ext/mcrypt, then /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

Again…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… extension=mcrypt.so

Restart Apache – you should be all set (again), according to phpinfo():