We climbed up then down El Capitan, yet little changed. We’re still in the Sierras, and there’s still work to do.
The following instructions are for peeps a) developing on macOS Sierra 10.12, b) need mcrypt for their PHP development i.e. PHPMyAdmin and/or encrypting personally identifiable data before storage (unlike your health insurer, Yahoo! and/or pretty much every other knucklehead out there), and c) do not want to recompile PHP or run MAMP. Mcrypt will load dynamically with PHP after completing this tutorial.
We begin by acquiring the following stuffs …
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.6.24 source code, which is available here; [NOTE: you may someday update OS X beyond 10.12, and PHP may get updated along with it; the author used 10.12, and PHP 5.6.24 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 8.0, which you can get from the App Store. You will also need the Command Line Tools (macOS 10.12) 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 (yea you need one of those too); 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.
But before we really wind up, let’s turn off System Integrity Protection (SIP):
- 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
NOTE: When you are done installing mcrypt, you can restart SIP by following the above steps while substituting
csrutil enable in step 4.
Create a directory at root called ‘sourceFiles’ (or something else you can remember) and drop items #1 and #2 in there. Then unzip them using the following commands …
- #1 –
tar -zxvf libmcrypt-2.5.8.tar.gz
- #2 –
tar -zxvf php-5.6.24.tar.gz
Next, move to the libmcrypt-2.5.8 directory, and type this in …
MACOSX_DEPLOYMENT_TARGET=10.12 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
make -j6 and finally
sudo make install.
libmcrypt prep complete. Now we build the PHP extension.
Jump back to /sourceFiles and down into php-5.6.24/ext/mcrypt …
Next we use Homebrew to install autoconf – if you haven’t done so before, just type
brew install autoconf. Then type
/usr/bin/phpize; you should see some output like so:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
Configure as follows, by typing the following …
MACOSX_DEPLOYMENT_TARGET=10.12 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 (with a “n” when it asks if you want to send a report), and last but not least
sudo make install.
Very last leg
Check for php.ini in the /etc directory. If all you see is php.ini.default, copy and paste it, then rename the copy to php.ini. Open it for edit. 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. Open in your favorite text editor – mine is firmly Sublime Text – and remove the “#” from in front of
LoadModule php5_module libexec/apache2/libphp5.so. Save – need permission – and close. Now restart Apache with
sudo apachectl start, and point your browser to the php info file I’m not going to tell you how to create.
phpinfo() what say you?
MG signing off (because macOS Sierra is not that rocky, but has proven useful in the Rockies)