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 (http://mxcl.github.com/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 …
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
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
make -j6, then
make test, and last but not least (again)
sudo make install.
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/libphp5.so.
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.