Plugging mcrypt into PHP, on Mac OS X Mountain Lion 10.8

Out with the old lion, in with the high altitude cat. Twice again, thanks goes out to previous commenters – this time it’s Mario, Max, and Rob, for the providing the right pieces to the puzzle. Onward…

The following instructions cater to those who a) are developing on OS X Mountain Lion 10.8.X, b) need the capabilities provided by mcrypt during their PHP development (such as installing Magento eCommerce), and c) do not want to completely recompile PHP or run MAMP. You’ll get mcrypt loading dynamically within PHP with these instructions.

First, you are going to 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 “Libmcrypt” then “2.5.8” and then chose the file named “libmcrypt-2.5.8.tar.gz”;

2) PHP 5.3.15 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.8.2 was being used. Use phpinfo() to check your version of PHP, and then download the PHP source for that version;

3) Xcode 4.5 tools, which you can pick up in the App Store; NOTE – you will also need the Command Line Tools (OS X Mountain Lion) 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;

and

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.

Go

First, create a directory at root called ‘SourceCache’ and dump the files from #1 and #2 in there and unwrap.

Move to the libmcrypt-2.5.8 directory, and punch in this…

MACOSX_DEPLOYMENT_TARGET=10.7 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…

make -j6

and finally…

sudo make install

libmcrypt is ready – now for the PHP extension…

Move back to /SourceCache, then down to php-5.3.15/ext/mcrypt – now STOP!

Xcode 4.5 doesn’t include autoconf, so if you haven’t installed it yet see “needs” #4 above to install Homebrew, and once that is done, type brew install autoconf. Now you can proceed…

Type /usr/bin/phpize.

Then configure as follows…

MACOSX_DEPLOYMENT_TARGET=10.8 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

Next: make -j6 then make test and finally sudo make install

Wrapup

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 a clean Mountain Lion install, 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… extension=mcrypt.so

Next: Enable PHP. PHP is not enabled by default – you will need to make a small modification to your /etc/apache2/httpd.conf file to get it going. You can do this with root power 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. Take your pick – all you have to do is remove the “#” from in front of LoadModule php5_module libexec/apache2/libphp5.so, then save.

Restart Apache, using sudo apachectl start. NOTE: this used to be as easy as selecting Web Sharing from within System Preferences, but that option is gone in OS X 10.8 Mountain Lion. Now you use the terminal window.

You should be all set (again), according to phpinfo():

php-5-3-15

php-streams

php-mountainlion-mcrypt

MG signing off (because despite all attempts to thwart, we have mcrypt running in PHP yet again)

Comments

  1. steve a says

    Thanks! Fairly straightforward guide, though I was able to enable mcrypt without using the configure options you lay out here.

  2. Patrik says

    Works like a charm! Except i thought skipping the step with downloading PHP was safe since I already have PHP up and running. But it doesn’t matter, so I was struggling a bit until I realized I needed the php source as well to make mcrypt install. So just follow the steps from start to finish and you’ll be fine.

    Thanks, Michael!

  3. wink says

    Followed the instructions but got an error on the phpize command. Returned the following:

    wink27:SourceCache wink$ /usr/bin/phpize
    Cannot find config.m4.
    Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module

    Continued on since I didn’t know what to do, but it didn’t install the extension as per phpinfo().

    Any ideas?

    Thanks!

    wink

  4. wink says

    Never mind. There wasn’t a step listed to cd to the ext/mcrypt folder before running the command. It shows up in phpinfo() now.

    Thanks for the help!

    wink

  5. says

    I think there is a small mistake, the first MACOSX_DEPLOYMENT_TARGET=10.7 in the article should be MACOSX_DEPLOYMENT_TARGET=10.8, right?

    Worked like a charm for me too. Thanks.

  6. Ryan Bagwell says

    I fumbled around with this for a day and a half. Kept getting an error about wrong architectures until I deleted the php source as well as the libmcrypt source and started over. These instructions magically worked after that.

  7. Sergio says

    Hi! I have a problem

    When I move to php-5.3.15/ext/mcrypt directory and I try to execute “MACOSX_DEPLOYMENT_TARGET=10.8 …”
    it says “./configure: No such file or directory”

    I alredy executed “Type /usr/bin/phpize”
    and the message was “/usr/bin/phpize is /usr/bin/phpize”

    What could be wrong?

  8. says

    Had trouble getting this to work with the Server.app on a Mac Mini Server running OS X 10.8.3 Mountain Lion. To get it working I had to:

    Copy mcrypt.so from
    /User/server/mcrypt/php5.3.15/ext/mcrypt/.libs/mcrypt.so
    to
    /usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so

    Now it works like a charm!

  9. Zoran says

    This is the best tutorial that can be found on this subject. I followed this tutorial twice, in the office and at home, and it worked great on both machines. Michael, my hat is down. Great job indeed.

    Thanks, Zoran

  10. Mike says

    Everything seems to work fine, until I get to the step after running /usr/bin/phpize and try to configure php with libmcrypt. This is what I’m running in the terminal and the output:

    MacBook-Pro:libmcrypt-2.5.8 ***************$ cd /Users/***********/downloads/php-5.3.6/ext/mcrypt
    MacBook-Pro:mcrypt ************$ /usr/bin/phpize
    Configuring for:
    PHP Api Version: 20090626
    Zend Module Api No: 20090626
    Zend Extension Api No: 220090626
    MacBook-Pro:mcrypt **************$ MACOSX_DEPLOYMENT_TARGET=10.7 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
    checking for grep that handles long lines and -e… /usr/bin/grep
    checking for egrep… /usr/bin/grep -E
    checking for a sed that does not truncate output… /usr/bin/sed
    checking for cc… cc
    checking for C compiler default output file name… a.out
    checking whether the C compiler works… yes
    checking whether we are cross compiling… no
    checking for suffix of executables…
    checking for suffix of object files… o
    checking whether we are using the GNU C compiler… yes
    checking whether cc accepts -g… yes
    checking for cc option to accept ISO C89… none needed
    checking how to run the C preprocessor… cc -E
    checking for icc… no
    checking for suncc… no
    checking whether cc understands -c and -o together… yes
    checking for system library directory… lib
    checking if compiler supports -R… no
    checking if compiler supports -Wl,-rpath,… yes
    checking build system type… i386-apple-darwin11.4.2
    checking host system type… i386-apple-darwin11.4.2
    checking target system type… i386-apple-darwin11.4.2
    checking for PHP prefix… /usr
    checking for PHP includes… -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
    checking for PHP extension directory… /usr/lib/php/extensions/no-debug-non-zts-20090626
    checking for PHP installed headers prefix… /usr/include/php
    checking if debug is enabled… no
    checking if zts is enabled… no
    checking for re2c… no
    configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
    checking for gawk… no
    checking for nawk… no
    checking for awk… awk
    checking if awk is broken… no
    checking for mcrypt support… yes, shared
    checking for libmcrypt version… >= 2.5.6
    checking for mcrypt_module_open in -lmcrypt… no
    checking for mcrypt_module_open in -lmcrypt… no
    configure: error: Sorry, I was not able to diagnose which libmcrypt version you have installed.

    I downloaded libmcrypt-2.5.8 and php-5.3.6, so I’m not sure why it is reading the version as 2.5.6. Maybe there is another older libmcrypt file floating around? If so, how do I find it and delete it and proceed? I am using Mac OS X 10.7.5.

  11. Tracy says

    I’m using OS 10.8.5, PHP 5.5.3, homebrew, and have command line tools. I followed everything fine until the php extension piece. This is what I have:

    checking for grep that handles long lines and -e… /usr/bin/grep
    checking for egrep… /usr/bin/grep -E
    checking for a sed that does not truncate output… /usr/bin/sed
    checking for cc… cc
    checking whether the C compiler works… yes
    checking for C compiler default output file name… a.out
    checking for suffix of executables…
    checking whether we are cross compiling… no
    checking for suffix of object files… o
    checking whether we are using the GNU C compiler… yes
    checking whether cc accepts -g… yes
    checking for cc option to accept ISO C89… none needed
    checking how to run the C preprocessor… cc -E
    checking for icc… no
    checking for suncc… no
    checking whether cc understands -c and -o together… yes
    checking for system library directory… lib
    checking if compiler supports -R… no
    checking if compiler supports -Wl,-rpath,… yes
    checking build system type… x86_64-apple-darwin12.5.0
    checking host system type… x86_64-apple-darwin12.5.0
    checking target system type… x86_64-apple-darwin12.5.0
    checking for PHP prefix… /usr/local/Cellar/php55/5.5.3
    checking for PHP includes… -I/usr/local/Cellar/php55/5.5.3/include/php -I/usr/local/Cellar/php55/5.5.3/include/php/main -I/usr/local/Cellar/php55/5.5.3/include/php/TSRM -I/usr/local/Cellar/php55/5.5.3/include/php/Zend -I/usr/local/Cellar/php55/5.5.3/include/php/ext -I/usr/local/Cellar/php55/5.5.3/include/php/ext/date/lib
    checking for PHP extension directory… /usr/local/Cellar/php55/5.5.3/lib/php/extensions/no-debug-non-zts-20121212
    checking for PHP installed headers prefix… /usr/local/Cellar/php55/5.5.3/include/php
    checking if debug is enabled… no
    checking if zts is enabled… no
    checking for re2c… no
    configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
    checking for gawk… no
    checking for nawk… no
    checking for awk… awk
    checking if awk is broken… no
    checking for mcrypt support… yes, shared
    checking for libmcrypt version… >= 2.5.6
    checking for mcrypt_module_open in -lmcrypt… no
    checking for mcrypt_module_open in -lmcrypt… no
    configure: error: Sorry, I was not able to diagnose which libmcrypt version you have installed.

    make -j6
    make: *** No targets specified and no makefile found. Stop.

    Suggestions?

    • says

      Suggestion – clean everything out and retry. On libmcrypt change MACOSX_DEPLOYMENT_TARGET=10.7 to MACOSX_DEPLOYMENT_TARGET=10.8; using 10.7 worked for me, but probably because my version was an upgrade that included some old libraries – upgrades always leave stuff behind. As we are over a year old here, chances are a lot of attempts are being done against factory/clean installs of the OS.

      Hope that helps.

  12. says

    The only tutorial I could find that walked through the steps and didn’t assume you were using MAMP. Finally got it working. Now it’s bookmarked.

    • says

      Cool. Never been much for black box solutions, whether technological or otherwise. If you can’t change it, patch it, update it, or fix it yourself when there’s a critical need, it simply isn’t worth possessing. At least not for this guy. Glad it worked for you.

Trackbacks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>