This is a guide for those who need to install (or re-install) mcrypt under PHP in OS X 10.7 (Lion).
You’ll need the following:
- PHP Source Code—Lion seems to ship with 5.3.6, you can get that here. You should double-check your version with
phpinfo()just in case. - libmcrypt 2.5.8 (yes, it really is from 2007). that’s here. I grabbed the bz2 version.
- Xcode 4.1 – supported on Lion; it’s available on the Mac App Store. You’ll still need an Apple Developer account to download the post-install updates.
- A place to uncompress and compile everything, move your php and libmcrypt downloads here.
- I usually use a directory in under my home named Source. In this case, I’m putting everything in a Lion specific folder:
/Users/sushi/Source/lion/
Now we need to uncompress our sources:
cd ~/Source/lion tar xvfj libmcrypt-2.5.8.tar.bz2 tar xvfz php-5.3.6.tar.gz
Let’s configure libmcrypt for installation:
cd libmcrypt-2.5.8 MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \ LDFLAGS='-O2 -arch i386 -arch x86_64' \ CXXFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \ ./configure --disable-dependency-tracking
Now let’s build and install libmcrypt itself.
make sudo make install
You can run make -j8 if you’re on a Quad-Core i7 and are curious how much it speeds up compilation, it makes no difference for installing mcrypt.
With libmcrypt ready to use, we need to compile the php extension for it.
cd ~/Source/lion/php-5.3.6/ext/mcrypt /usr/bin/phpize MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \ LDFLAGS='-O2 -arch i386 -arch x86_64' \ CXXFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \ ./configure --with-php-config=/Developer/SDKs/MacOSX10.7.sdk/usr/bin/php-config make sudo make install
Everything should be ready to hook up at this point, we’ll need to update /etc/php.ini to tell php to load the extension.
Verify that /etc/php.ini exists. If you’ve never worked with it before, or have just upgraded to Lion, you’ll need to copy php.ini.default to php.ini with:
# skip this step if /etc/php.ini already exists. sudo cp /etc/php.ini.default /etc/php.ini
Update php.ini and tell php to load our newly compiled mcrypt.so
sudo nano /etc/php.ini
Add the following to the end of the file, then save and exit:
extension=mcrypt.soNow restart Apache:
- Open System Preferences
- Select Sharing
- Uncheck and re-check “Web Sharing”—this restarts the web server.
- For some reason my Web Sharing was unchecked even though Apache was already running, if this happens to you, just “check/uncheck/check” to make sure it’s actually restarted.
Verify in your phpinfo() that mcrypt is really there, it should look like this:
~Enjoy!


Doesn’t work. where exactly should I be with this command? in the mcrypt directory or the phpsize directory
cd ~/Source/lion/php-5.3.6/ext/mcrypt
/usr/bin/phpize
You’ll want to be in the ext/mcrypt directory when you run phpize. If you still get an error post it here, I’ll see what I can make of it.
Thanks .. you save my time … trying to run after the lion
( I upgraded my MacBook .. some pieces still under 32bits w SL .. so need to recompile them to 64)bits w last dev kit …
Thanks for the great instructions!
I found several websites that tried to explain how to do this and yours was the only one that had instructions that a newbie like me could follow. Thank you for taking the time to document and share this information. You saved me a lot of headaches.
I got this working just fine on our Lion server but I am having some trouble on SL server 10.6.8. Can you please tell me what modifications I need to make? I tried to modify the command in step 2 but changing the deployment target to 10.6 but it returned an error.
checking for C++ compiler default output file name… configure: error: C++ compiler cannot create executables
See `config.log’ for more details.
Ugh, nevermind, I forgot to install Xcode.