We made our way into the park. Now we do some climbing.
The following instructions are for those a) developing on OS X El Capitan 10.11.X, b) need mcrypt for their PHP development (think PHPMyAdmin, Magento eCommerce or just twisting _RIJNDAEL_256 for shits and giggles), and c) are unwilling to recompile PHP from scratch or run an alternative development package set such as MAMP. Mcrypt will load dynamically with PHP by venturing forth.
Before beginning acquire the following stuff …
1) libmcrypt-2.5.8, which you can find here; download by clicking the one of the two file links (author used “libmcrypt-2.5.8.tar.gz”);
2) PHP 5.5.27 source code, which is available here; [NOTE: you may someday update OS X beyond 10.11, and PHP may get updated along with it; the author used 10.11, and PHP 5.5.27 was included with that OS version. If necessary use
php -v to check your version of PHP and then download the PHP source for that version.];
3) Xcode 7.0.1, which you can get from the App Store. You will also need the Command Line Tools (OS X 10.11) 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 (and if you don’t have one of those, get one); and
4) Homebrew (http://brew.sh) which can be installed by typing
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/ install/master/install)" at the command line.
Now we get down to business …
Open Thy Terminal
Create a directory at root called ‘sourceFiles’ and drop the items from #1 and #2 in there. Unzip them.
Move to the libmcrypt-2.5.8 directory, and type this in …
MACOSX_DEPLOYMENT_TARGET=10.11 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 finally …
sudo make install
You are done with libmcrypt; now for the PHP extension.
Move back to /sourceFiles, then down to php-5.5.27/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.11 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 (again)
sudo make install.
***Chances are when you hit that last command you may run into an “operation not permitted” error. This is caused by OS X’s new System Integrity Protection a.k.a. SIP, which doesn’t allow writes to the /usr/lib/.. directory. You’ll have to disable SIP, then do the
sudo make install over again. See the notes at the bottom of this tutorial for how to turn off SIP.
Final (FINAL!) leg
Make sure you have php.ini in the /etc directory – it may be called php.ini.default, particularly if you’ve just done an upgrade to El Capitan or are working with recent clean installation. Copy and paste it, then rename the copy to php.ini. Open it; make sure
enable_dl = On, and add a single line to the Dynamic Extensions section:
You now enable PHP by modifying your /etc/apache2/httpd.conf file. You can use vim or emacs – this author just dug it up via Finder, then edited with Sublime Text – you’ll have to provide permissions password before saving. The sole change … removing the “#” from in front of
LoadModule php5_module libexec/apache2/libphp5.so.
Restart Apache with
sudo apachectl start.
phpinfo() will tell the story:
MG signing off (because El Capitan is not that tall … just a bit steep)
NOTE ON SIP: Turning off SIP is pretty easy – just follow these steps:
- Click the Apple menu (upper left hand corner of your screen)
- Select Restart, then hold down the Command-R keys to boot into Recovery Mode
- Select the Utilities menu and then Terminal
- In Terminal, type
csrutil disableand then hit return; then close Terminal
- Click the Apple menu and select Restart
When you are done installing mcrypt, you can reinitiate SIP by following the instructions above, but using
csrutil enable in step 4.