Add mcrypt to Mac OS X (Snow Leopard 10.6, Lion 10.7, Mountain Lion 10.8)

You can easily install the mcrypt extension to PHP5 on Mac OS X Server. Here’s how:

OSX-Mavericks-Icon

Mavericks Instructions

If you’re running Mac OS X Mavericks Server, see these articles about adding PHP extensions:

If you’ve previously installed this extension using instructions on this page, read this article to upgrade PHP extensions for Mavericks server.

Download and install MacPorts from http://macports.org.

The following steps are performed in the Terminal:

Force MacPorts to update:

sudo port -v selfupdate

Now, build mcrypt:

sudo port install php5-mcrypt

Copy the newly created shared object for mcrypt into Mac OS X’s default PHP5 extension directory:

sudo cp /opt/local/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Next, you need to edit php.ini to add the extensions. Find the phrase Dynamic Extensions, and add:

extension=mcrypt.so

And finally, restart Apache:

sudo apachectl restart

To confirm installation, create a new PHP document called phpinfo.php with the following contents:

<?php
 phpinfo();
?>

Point your browser to the URL of that file. If all went well, you’ll see this block:

mcrypt installed in Mac OS X Server’s native PHP5

5 thoughts on “Add mcrypt to Mac OS X (Snow Leopard 10.6, Lion 10.7, Mountain Lion 10.8)

  1. Pingback: izurunet????????/?????????? | izurunet????????

  2. Worked like a charm. What’s great about this technique is that you retain the core Apache for OS X and use MacPorts’ build scripts to compile a platform-specific mcrypt without having to do much.

    If you ever want to undo anything, just remove the ports and the copied mcrypt.so and it’s like nothing ever happened.

    Highly suggest this method unless you really feel like you need to rebuild PHP manually.

  3. THANK YOU VERY MUCH!

    This worked for me, and was waaaaay easier than some of the other solutions I’d found on the ‘net.

    One issue I did encounter was this error when I tried to run “sudo port install php5-mcrypt”:

    Error: Dependency ‘p5.12-locale-gettext’ not found.

    A bit of Googling came up with a simple solution: re-run the selfupdate command:

    sudo port selfupdate

    This generates the following innocuous output:

    —> Updating MacPorts base sources using rsync
    MacPorts base version 2.0.3 installed,
    MacPorts base version 2.0.3 downloaded.
    —> Updating the ports tree
    —> MacPorts base is already the latest version

    The ports tree has been updated. To upgrade your installed ports, you should run
    port upgrade outdated

    However, this also resolves the p5.12-locale-gettext problem, allowing the php5-mcrypt install to complete without errors.

    Thanks again, Chris Brewer.

  4. Beautiful. Been trying to install mcrypt with SL Server the whole day and had nothing but one issue after another trying to recompile. Nothing but errors, no matter where I turned. If only I’d found this earlier. Thanks for the post.

Leave a Reply

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