Menu

Michael Gracie

Plugging mcrypt into PHP, on Mac OS X El Capitan 10.11

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

then …

make -j6

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 /usr/bin/phpize.

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

Repeat 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: extension=mcrypt.so

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:

phpver5-5-27

phpstreams5-5-27

php-elcapitan-mcrypt

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:

  1. Click the Apple menu (upper left hand corner of your screen)
  2. Select Restart, then hold down the Command-R keys to boot into Recovery Mode
  3. Select the Utilities menu and then Terminal
  4. In Terminal, type csrutil disable and then hit return; then close Terminal
  5. 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.

Comments

Jaakko says:

Getting an error when running make -j6 for the second time?
/sourceFiles/php-5.5.27/ext/mcrypt/mcrypt_filter.c:21:10: fatal error: ‘php.h’ file not found

Not sure what you mean by “second time” – please explain.

Jaakko says:

Reinstalling xcode commandline tools did the trick. Now I’m having other problems like mcrypt not showing up in phpinfo. Tried with full path, still nothing. Maybe it has something to do with the fact that previous version of mcrypt was installed using macports. I did uninstall Macports before updating .

Ariel says:

Same Here.
Follow every step multiple times … but when I do the “make -j6 ” under PHP folder I got : “mcrypt_filter.c:21:10: fatal error: ‘php.h’ file not found” every time, any Idea ?.

Start fresh i.e. delete the source folders, and unzip from download. And make sure autoconf ran correctly – see Chris thread below for more.

Chris says:

Thanks for the guide. I just get the following error: “Cannot find config.m4.
Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module”. Any ideas?

What directory were you in when you ran /usr/bin/phpize ? And did you get output that looked ok i.e. no pile of error messages and blank spaces where it seems there should have been data? Should have been a couple lines at the end that said something like ‘Zend Extension blah blah: blah numbers blah’ (fyi .. I just can’t reproduce a precise example right this moment).

UPDATE: Should end with something like this …

Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:

… only with data after the colons.

Chris says:

I get the message whilst within the php-5.5.27 directory. There’s no other messages but: “Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module”.

Ariel says:

I’m doing the phpize in the right folfer (/etc/mcrypt), this is what I Got.
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:

Ariel says:

Next step ends like this :
creating libtool
appending configuration tag “CXX” to libtool
configure: creating ./config.status
config.status: creating config.h

Ariel says:

and “Make -j6” in /ext/mcrypt ends like this :
sourceFiles/php-5.5.27/ext/mcrypt/mcrypt_filter.c:21:10: fatal error: ‘php.h’ file not found
#include “php.h”
^
/Users/…../Downloads/sourceFiles/php-5.5.27/ext/mcrypt/mcrypt.c:25:10: fatal error: ‘php.h’ file not found
#include “php.h”
^
1 error generated.
make: *** [mcrypt_filter.lo] Error 1
make: *** Waiting for unfinished jobs….
1 error generated.
make: *** [mcrypt.lo] Error 1

Error at phpize … you could have stopped right there as no need to continue with the process when you get an error right up front.

I’m going to assume you had brew in place before upgrading to El Capitan. So uninstall brew, re-install it, then re-install autoconf.

Joven says:

I’m monitoring this page, and i have the same error with Chris.

Error at phpize… I already reinstall brew but still I wasn’t able to enable the mcrypt.

Kaupo says:

Make sure you have Xcode Command Line Tools installed:
xcode-select –install

Chris says:

Doh! So stupid, I’m in the wrong folder!

@Joven – Try clearing all previously manipulated source, disabling SIP, and then starting again from the tar balls. I did wind up reinstalling brew (and autoconf) at the phpize step, but thought it too machine specific to note.

Oma Cox says:

Warning: autoconf-2.69 already installed, it’s just not linked – I get this after I do the $ brew install autoconf – in the mcrypt – how do it get it to link?

Singgih Octafianto says:

Hi, thanks for the guidance.
Works for me. Just read and follow the steps and found out that sourceFiles directory is created at root. I did chown -R user:group /sourceFiles/ and the rest is working.

Perfect, this is the only thing that DID work, after trying a bunch of different things for a couple of hours.

To get around SIP, you can copy the mcrypt.so file to /usr/local/lib and then put extension=/usr/local/lib/mcrypt.so into php.ini

Ernst says:

Thank you so much for this guide. Works like a charm.

Would it also be necessary to update the php.ini-development and php.ini-production files?

1) You’re welcome. 2) Not unless you plan on using them.

Leave a Reply

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