Michael Gracie

Plugging mcrypt into PHP, on Mac OS X Yosemite 10.10

Mavericks rode in on Mountain Lions, but the park ranger at Yosemite wouldn’t let them in. “We need mcrypt” they said, “And we don’t want to recompile PHP!” The ranger handed them a map, and it led them here.

The following instructions are for those a) developing on OS X Yosemite 10.10.X, b) need the capabilities provided by mcrypt during their PHP development (like using PHPMyAdmin or Magento eCommerce), 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, grab the following bits …

1) libmcrypt-2.5.8, which you can find here; download libmcrypt (not mcrypt!), by clicking the link labeled “libmcrypt-2.5.8.tar.gz” on the SourceForge page;

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

3) Xcode 6.1, which you can get from the App Store. You will also need the Command Line Tools (OS X 10.10) for XCode, which you get by selecting “Xcode/Open Developer Tool/More Developer Tools..” from the Xcode menu, then logging into your Apple Developer account (yes, you need one of those too);


4) Homebrew ( which can be installed by typing ruby -e "$(curl -fsSL https://raw.githubusercontent
.com/Homebrew/install/master/install)" at the command line.

Now for the down and dirty…

Ride On, with Terminal

Start by creating a directory at root called ‘sourceFiles’ and drop the files from #1 and #2 in there. Unzip at will.

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

MACOSX_DEPLOYMENT_TARGET=10.10 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 last but not least …

sudo make install

You are done with libmcrypt; the PHP extension is up next.

Move back to /sourceFiles, then down to php-5.5.14/ext/mcrypt …

You now get to use Homebrew to install autoconf – if you haven’t done so for some other reason already, just type brew install autoconf.

When that’s done, type /usr/bin/phpize.

And configure as follows …

MACOSX_DEPLOYMENT_TARGET=10.10 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

Repeat make -j6, then make test, and last but not least (again) sudo make install.

Home stretch

Make sure you have php.ini in the /etc directory – it will probably be called php.ini.default if you’ve just done an OS X upgrade or are working with a new Yosemite installation. Just rename to php.ini. Make sure enable_dl = On; do not remove the ; from in front of ;extension_dir = "./". Add a single line to the Dynamic Extensions section:

You now enable PHP, which is disabled by default (for upgrades and new installs). You’re going to edit your /etc/apache2/httpd.conf file for this. Options include superuser role play from the terminal using vim or emacs; or you can change the permissions on the file itself (and the directories above) via Finder, edit with XCode, then return the permissions to read-only afterward. The sole modification needed is removing the “#” from in front of LoadModule php5_module libexec/apache2/

Restart Apache like so: sudo apachectl start.

You should be rockin’, according to phpinfo():




MG signing off (because mcrypt is good to go, and your hiking boots don’t need new soles either)

Editor’s note: Thanks to those who emailed about this test/tutorial; Yosemite was not brought on board here earlier because it was giving R & RStudio fits. Those issues just got cleared up, and your patience was/is appreciated.


Thanks a lot for sharing this, saved me a lot time. Regards from Venezuela!

You are quite welcome Hector.

Mert Salık says:

Thank you for “really work instructions”.
best regards

[…] Link para o artigo original em Inglês: Plugging mcrypt into PHP, on Mac OS X Yosemite 10.10 […]

Andrea says:

The best tutorial on the web I’ve found. Thanks!

And thank you too. Glad it helped.

William Peterson says:

I just upgraded to OS X 10.10 Yosemite and when to start my web development only to find that mcrypt was not already baked in. I searched for two days (roughly) trying many different suggestions from many different sites only to have them fail. This is the ONLY site that provides clear and concise information with the end result being a success!

Thank you.

This is a series going back to Leopard. Along the way I’ve picked up a lot of tips, particularly from some of the commenters here, that have made life easier. So really, thanks all around.

Like the others said, it worked. Thank you for taking the time to write about this, it really helped.

Vasko says:

Thank you very much and it worked as stated on every step cheers!!

maks says:

Hi, thatks for tutorial.
After this steps I run `php -i | grep mcrypt` and I see that it’s installed.
But when i `cd` to my project’s folder, this command returns empty string, so it seems like mcrypt is installed (accordint to php -i) only form sourceFiles/php-xx folder.

Do you know what is the problem?

Welcome. What does php info say?

flashsky says:

It really works when you upgrade or new installs .
Save our time from compiling php source code.
Thank you very much.

I usually manage PHP via homebrew-php, but for some reason, I couldn’t get `brew install php56-mcrypt` to install properly, with it always giving the following error:

==> ./configure –prefix=/usr/local/Cellar/php56-mcrypt/5.6.8 –with-php-config=/usr/local/opt/php56/bin/php-config –with-mcrypt=/usr/local/opt/mcrypt
checking for mcrypt support… yes, shared
checking for libmcrypt version… >= 2.5.6
checking for mcrypt_module_open in -lmcrypt… no
checking for mcrypt_module_open in -lmcrypt… no
configure: error: Sorry, I was not able to diagnose which libmcrypt version you have installed.

Simply following your first step (I.e., compiling mcrypt from source) allowed me to then install php56-mcrypt via Homebrew.

Graham Gillett says:

Hi Michael

This is probably the third or fourth time I have needed to use these instructions to install mcrypt going back to Snow Leopard, and they have worked perfectly every time. A big thank you for taking the time to share this information, which has been a big time saver for me.



Moe says:

Fuck yeah! Thank you so much – made me so mad
Really really thank you: Who knows maybe soon you’ll somehow visit Düsseldorf(Ger) – If it will be so, don’t look for an Hotel! You can then sleep here 😉

Thanks for the detailed description! Works perfectly now.

Leave a Reply

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