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 (http://mxcl.github.com/homebrew/) which can be installed by typing
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go/install)" 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
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.
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
make -j6 then
make test and finally
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 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/libphp5.so 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)