Plugging mcrypt into PHP, on Mac OS X Mavericks 10.9

The big cats are gone; the Mavericks are now in charge. But that doesn’t mean the need for mcrypt with your PHP applications requires marching perpetually to the beat of a different drum.

The following instructions are for those a) developing on OS X Mavericks 10.9.X, b) need the capabilities provided by mcrypt during their PHP development (Magento eCommerce comes to mind), and c) do not want to recompile PHP from scratch or run MAMP. Mcrypt will get loaded dynamically with PHP by following these instructions.

Before you begin, you will need a few things…

1) libmcrypt-2.5.8, which you can pick up here; make sure to get libmcrypt and not mcrypt – to do this, click the link labeled “libmcrypt-2.5.8.tar.gz” on the SourceForge page;

2) PHP 5.4.17 source, which you grab here; NOTE – you may update your OS X at some point, and PHP may get updated along with it – for the author’s run OS X 10.9 was being run, and PHP 5.4.17 is what’s included with that OS version; if necessary use phpinfo() to check your version of PHP and then download the PHP source for said version;

3) Xcode 5.0.1 tools, which you can get from the App Store; NOTE – you will also need the Command Line Tools (OS X Mavericks) for XCode, which you can pick up by selecting “Xcode/Open Developer Tool/More Developer Tools..” from the Xcode menu, then logging into your Apple Developer account;


4) Homebrew ( which can be installed by typing ruby -e "$(curl -fsSkL" ruby -e "$(curl -fsSkL" at the command line; you may already have this if you followed the mcrypt instructions for Mountain Lion – if that is the case it should still work.

Collect, then get down to business.

Ready Set Go

First, create a directory at root called ‘SourceCache’ and dump the files from #1 and #2 in there and unzip.

Move to the libmcrypt-2.5.8 directory, and type this in…

MACOSX_DEPLOYMENT_TARGET=10.9 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…

Move back to /SourceCache, then down to php-5.4.17/ext/mcrypt – then pause for this word from your local affiliate…

Xcode doesn’t includes autoconf, so if you haven’t installed it yet see “needs” #4 above to acquire Homebrew; once that is done, type brew install autoconf.

Now continue…

Type /usr/bin/phpize.

Then configure with this…

MACOSX_DEPLOYMENT_TARGET=10.9 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=/usr/bin/php-config

Follow-up with make -j6 then make test and finally sudo make install

Check PHP

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 an OS X upgrade or are working with a new Mavericks installation, 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:

Then enable PHP, which is not so by default. To do this you make a modification to your /etc/apache2/httpd.conf file. This can be done with superuser from the terminal using vim or emacs, or you can change the permissions on the file itself and the directories above from Finder info, then edit in XCode, and return the permissions to read-only thereafter. However you go about it, the goal is removing the “#” from in front of LoadModule php5_module libexec/apache2/ and saving the change.

Restart Apache, using sudo apachectl start. NOTE: this used to be as easy as selecting Web Sharing from within System Preferences, but that option disappeared in OS X 10.8 Mountain Lion – now you use the terminal window.

You should be set, according to phpinfo():




MG signing off (because mcrypt is now running in PHP, and nobody had to scream in the boardroom)


Sanjib says:

Have been following your mcrypt installation instructions ever since Snow Leopard, Lion and Mountain Lion days. Now Mavericks. Works perfectly every single time. What’s more, I don’t have to hold my breath πŸ™‚

Much appreciated Sanjib.

Joao Ramos says:

Works like a charm!
Thanks a lot.

[…] the details in Plugging mcrypt into PHP, on Mac OS X Mavericks 10.9 by Michale Gracie. In […]

Brian says:

I am so glad that there are people in the world like you. Really, if you had not created this post, then mcrypt simply would not be working for me, I would be fired and then completely destitute in three months. THANK YOU

Well in that case, you are especially welcome. And, if you’d like to provide a big tip, please stash it in a brown paper bag and leave it in my alley. πŸ˜‰

jimmy says:

Hi , I am following your mcrypt installation instructions in Mavericks, but I got a fatal error when I build php-5.4.17/ext/mcrypt in step make -j6, the error message as bellow.
Jimmys-Macbook-Air:mcrypt jiangdetian$ make -j6
/bin/sh /Users/jiangdetian/Downloads/php5417/ext/mcrypt/libtool –mode=compile cc -I. -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt -DPHP_ATOM_INC -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt/include -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt/main -I/Users/jiangdetian/Downloads/php5417/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/jiangdetian/Downloads/php5417/ext/mcrypt/mcrypt.c -o mcrypt.lo
/bin/sh /Users/jiangdetian/Downloads/php5417/ext/mcrypt/libtool –mode=compile cc -I. -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt -DPHP_ATOM_INC -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt/include -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt/main -I/Users/jiangdetian/Downloads/php5417/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/jiangdetian/Downloads/php5417/ext/mcrypt/mcrypt_filter.c -o mcrypt_filter.lo
cc -I. -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt -DPHP_ATOM_INC -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt/include -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt/main -I/Users/jiangdetian/Downloads/php5417/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/jiangdetian/Downloads/php5417/ext/mcrypt/mcrypt_filter.c -fno-common -DPIC -o .libs/mcrypt_filter.o
cc -I. -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt -DPHP_ATOM_INC -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt/include -I/Users/jiangdetian/Downloads/php5417/ext/mcrypt/main -I/Users/jiangdetian/Downloads/php5417/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/jiangdetian/Downloads/php5417/ext/mcrypt/mcrypt.c -fno-common -DPIC -o .libs/mcrypt.o
/Users/jiangdetian/Downloads/php5417/ext/mcrypt/mcrypt_filter.c:21:10: fatal error:
‘php.h’ file not found
/Users/jiangdetian/Downloads/php5417/ext/mcrypt/mcrypt.c:25:10: fatal error:
‘php.h’ file not found
#include “php.h”
#include “php.h”
1 error generated.
make: *** [mcrypt_filter.lo] Error 1
make: *** Waiting for unfinished jobs….
1 error generated.
make: *** [mcrypt.lo] Error 1

I think some of configure is missing, but I can find out. Could you help me? Thank a lot!

Clean all the files out, reboot, and start over. Follow the directions to the “T” – they work.

Felipe Butcher says:

Your are a life saver! thanks!

SpinFighter says:

I followed you guide to the “.”, but I cannot see the mcrypt in the phpinfo. I have double-checked that the php files have been updated correctly. Do you have an idea where I should start to look for the glitch?

Thanks in advance.

First thought is figuring out if you are looking at the correct php test page i.e. what directory did you put it in and where you are pointing your browser. I’ve made that mistake before. Next would be making sure any and all permissions are set (or reset) correctly. Lastly, I’d dump everything (everything) and start from scratch, documenting each step on paper (directly after completing it) and also recording the results i.e. any errors you see in terminal.

You will probably find an obscure misstep along the way – that’s usually how these things happen.

Dave says:

Great information. Just one small update… Your link to Homebrew needs to be changed from ruby -e "$(curl -fsSkL" to ruby -e "$(curl -fsSkL"

Judd Lyon says:

A sincere thank you. I always cringe when I find myself copy/pasting install scripts, but this worked perfectly. You are awesome.

Kyle says:

You sir are an absolute hero!

This has been causing me nightmares for toooooo long, your guide worked perfectly.

Thank you. Glad it worked out.

This is the ONLY guide that actually worked for me. Thank you for your help!

Such a pain but you made it easy and is the only thing that has gotten it to work so far! Thank you so much!

Michael says:

You, my sir are owed coffee, beers at least a firm virtual handshake. These instructions worked SO smoothly.. and it worked.

You’re the man! Thank you!

You are quite welcome.

Sanjib says:

By the seven gods, works like a charm in Yosemite (preview version) too πŸ™‚
The only obvious thing I changed was: MACOSX_DEPLOYMENT_TARGET=10.10

Alexandre Rio says:

Thank you so much, great tutorial !

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.