Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /data/sites/web/remonpelnl/www/wp-content/themes/remonpel_nl__child__twentyfourteen/functions.php on line 32
Adding MCRYPT to your OSX based PHP server setup – Remons TechNotes

Adding MCRYPT to your OSX based PHP server setup

[UPDATE]: Updated for OSX 10.10 Yosemite [/UPDATE]

In my attempts to run phpMyAdmin on my development Mac I found this tutorial but, alas, it didn’t work. It resulted in numerous errors (like this one: lipo: can’t figure out the architecture type of: /var/folders/v6/nrfc_5hn12g91vzw8vff44m00000gn/T//cchRI7wl.out) and, as you guessed, the mcrypt extension did not work.

This post is the third post in a series to build the “perfect” setup. See ‘The “Ultimate” Guide …’ for a complete list. It is also referenced from the first post in this series, so you MIGHT already have done this :)

Choose OSX Version: 10.6 | 10.7 | 10.8 | 10.9 | 10.10 | 10.11

I found this tutorial and it works… sort of… and because it’s not entirely correct, I have copied and pasted a bit and now it is correct :) Also the tutorial is for 10.6 and we’re on 10.7, so I have compensated for that as well.

Of course, this is based on my (now defunct) OSX Lion 10.7 installation and I have Xcode 4 for Lion installed.

Preparation

Fire up your terminal and do this;

Shell commandphp --version

Now you will see the version number of your PHP; you will need to match the source version with this. Mine is 5.3.6 for PHP and I downloaded the 2.5.8 version of mcrypt. If you use different versions, then substitute the correct version numbers.

Shell commandmkdir /tmp/source && cd /tmp/source
curl --location -s http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download | tar -zx
curl --location -s http://nl3.php.net/get/php-5.3.6.tar.gz/from/nl1.php.net/mirror  | tar -zx
Installation

Shell commandcd /tmp/source/libmcrypt-2.5.8
MACOSX_DEPLOYMENT_TARGET=10.6 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
sudo make install

Shell commandcd /tmp/source/php-*/ext/mcrypt/
phpize
MACOSX_DEPLOYMENT_TARGET=10.6 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=/Developer/SDKs/MacOSX10.6.sdk/usr/bin/php-config
make -j6
sudo make install

Possible errors

You may encounter a problem during build if some C modules aren’t available. If you get an error like this

Possible errorerror: 'PHP_FE_END' undeclared here (not in a function)
. You can avoid this by editing the file mentioned in the error message and replace all occurrences of PHP_FE_END with {NULL,NULL,NULL} .

Same thing might happen with function ZEND_MOD_END .

After fixing, issue the commands

Shell commandmake -j6
sudo make install

This should build now.

I have no idea what effect this will have on the end-result, but at least it builds :)

Thank you, Homer, for this great tip.

Cleanup

now remove the temporary files

Shell commandcd ~ && rm -rf /tmp/source

Activation

Edit your PHP configuration

Shell commandsudo nano /etc/php.ini

if “New file” is shown, please copy php.ini.default to php.ini first.

Shell command[ ! -f "/etc/php.ini" ] && sudo cp /etc/php.ini.default /etc/php.ini

other tutorials tell you to set

enable_dl=on
but do NOT, I repeat NOT do that; the DL function is deprecated and limited to a few extensions anyway, so you do NOT need this. Just add this line on the bottom of your php.ini;

extension=mcrypt.so

Some versions of OSX come with a default php.ini with an mcrypt section (mine does in 10.8 and 10.9, but did NOT in 10.7 which was an upgraded 10.6 which was an upgraded 10.5…) and it MIGHT be needed to put this line in the mcrypt section. In NANO, you can search with CTRL+W. (Thank you Joshua)

Now restart your Apache

  1. click Apple > System Preferences > Sharing
  2. disable Web Sharing
  3. enable Web Sharing

If Web Sharing won’t come on, retrace your steps, you must have missed an error message.

If all goes well, Web Sharing will turn on

in your terminal type

Shell commandphp --info | grep crypt

you should see:

Shell outputmcrypt support => enabled

Now you’re done!

Footnotes:

August 2014: Updated for OSX 10.10 Yosemite

July 2013: Updated for OSX 10.9 Mavericks

Author: Remon Pel

WebDeveloper though not WebDesigner

58 thoughts on “Adding MCRYPT to your OSX based PHP server setup”

    1. the part:
      “You can avoid this by editing the file mentioned in the error message and replace all occurrences of PHP_FE_END with {NULL,NULL,NULL} ”

      solved my problem …THANK YOU!

  1. Thanks for this post. Really helpful in getting libmcrypt.so up for php.

    Some of us may still be getting an error in make (php-5.3.x/ext/mcrypt) that goes like this–

    /tmp/source/php-5.3.8/ext/mcrypt/mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)
    /tmp/source/php-5.3.8/ext/mcrypt/mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)
    lipo: can’t figure out the architecture type of: /var/folders/yx/mjbztxd5115_557vh6bz45p80000gn/T//ccipgsqR.out
    make: *** [mcrypt.lo] Error 1

    Solution is to open mcrypt.c and replace PHP_FE_END with {NULL,NULL,NULL}. I got this from here

    Peace!

    1. For some reason, the installed copies of main/php.h, Zend/zend_API.h and Zend/zend_modules.h are missing the PHP_FE_END, ZEND_FE_END and ZEND_MOD_END macros, respectively. (Look for the headers in /usr/include/php.) Instead of patching individual extensions, you can replace the installed headers with ones from the source distribution for your version of PHP, though you should first check that there aren’t any incompatible changes (the differences should be fairly minimal). This will fix building every extension that uses these macros.

  2. Remon! You are my hero!
    I spent many hours follow many tutorials on the internet to set mcrypt up but none of them works. I am just so frustrated until I find your post! All the things other tutorial said is right but except enable_dl=On, enable_dl=Off should keep! It works like magic now, you made my day!

  3. Hi Remon,

    Thanks for this post.

    I did all the steps, but mcrypt module does not work yet.

    Please, could you help me?

    My configs:
    1. /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so

    2. (locate mcrypt.so) /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so

    3. (php.ini)
    extension_dir=”/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/”
    extension=mcrypt.so

    And after restart Apache, the command “php -info | grep crypt” returns nothing.

    Have you any idea?

    Thank you for advance.

    1. Instead of setting the extension_dir, set the full path in the extension= line, so make it;

      extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so

      and see if that works.
      Ow, and please note; I did NOT have to do this. Just make and install both packages and add extension=mcrypt.so to PHP.ini and all done.

  4. First off the unpacking the Tarballs doesn’t work as indicated on this, I tried to get the latest versions for both the libmcrypt and php 5.3.8 from sources.

    1. Hi again, Mike, I noticed, when re-testing the commands to build and install MCrypt, that wordpress messed up the commands; a double dash would be replaced with a single dash which, of course, broke the commands. I have fixed this and re-tested all steps and it works out perfectly. Please try again.

  5. Hello and thank you very much for this tutorial. Please note that I had a hard time – not following the instructions, they are great! But with my OS X Lion 10.7.3 Server with 5.3.8 php.

    First and foremost when you download and run the Xcode app from the App store the command line tools are not installed. You need to launch Xcode.app, go to preferences and then download tabs and download and install the command line tools package (thanks to http://www.macobserver.com/tmo/article/install_the_command_line_c_compilers_in_os_x_lion/).

    After that I was able to install libmcrypt without a problem (be careful not to use the mcrypt package, but libmcrypt!:). Also my PHP version is 5.3.8, so I downloaded the 5.3.8 source. I went into the ext/mcrypt directory inside the 5.3.8 source and typed phpize and I got some error involving autoconf. After some digging I found this site (thank you: http://www.spiration.co.uk/post/1385/Cannot-find-autoconf.-Please-check-your-autoconf-installation) and installed m4 (1.4.16) and autoconfig (2.68). Thank you, Thank you, Thank you!

    Then back into php-5.3.8/ext/mcrypt and follow the rest of the instructions (phpize… etc etc).

    It worked. Thank you so much!

    Mr. L

  6. When using just the “Command Line Tools” from Apple without installing Xcode the command for configuring the mcrypt extension should be:

    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

    The change is in the –with-php-config parameter.
    (RED: Command line tools are available with a Mac Developer account from Apple: https://developer.apple.com/downloads/index.action?=command%20line%20tools)

  7. With small adjustments for locate of php-config, changing 10.7 to 10.8, and php to 5.3.13 (standard for Mountain Lion) these instructions allowed me to re-install mcrypt on Mountain Lion install.

    Much appreciated!

    1. Thank you too! You inspired me to update the post and even made it multi-version; just pick the version you’re on and the instructions change accordingly :)

  8. Wow! Thanks for this great tutorial. It worked like a charm the first time. My new MBP is now setup for web development and all is right in the world. Thanks again!

  9. I installed php 5.4.8 prior to reading this, I had to install mcrypt for Laravel, but I can’t seem to cd into the /tmp/source/php-5.4.8/ext/mcrypt/
    and when I looked around I only see the libmcrypt-2.5.8
    am I missing something?
    oh I’m on 10.7.5

  10. Which one do I use if I am running 10.7.5, and PHP 5.4.8
    I need the mcrypt to run Laravel, I tried the one for 10.7 and 10.8 and can’t build either?

    Thanks

  11. I am trying to follow this, but when I use “make -j6” I get “sudo make command not found”.

    1. the reply is really “sudo make command not found” ?? in that case you would have typed “sudo make -j6” which is not the correct command, it should be just “make -j6” but that should not be a problem – at least the make command should respond… The make command is usually in “/usr/bin”, please verify you have the make command by typing “which make” and it should reveal “/usr/bin/make”.

      Sorry I don’t have a straight answer for you at the moment, but hopefully you’ll figure it out :)

  12. Thanks for this tutorial! It was a great help!

    Maybe it is worth mentioning that autoconf needs to be installed. I had some difficulties configuring mcrypt because of this error. Following error was reported:

    Cannot find autoconf. Please check your autoconf installation and the
    $PHP_AUTOCONF environment variable. Then, rerun this script.

    I fixed it using following commands:

    cd /tmp/source
    curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
    tar xvfz autoconf-latest.tar.gz
    cd autoconf-2.69/
    ./configure
    make
    sudo make install

    Info found on this website:
    http://www.coolestguyplanettech.com/how-to-install-mcrypt-for-php-on-mac-osx-lion-10-7-development-server/

    Kind regards!

    1. Thanks for the addition. Strangely enough, I never had to install autoconf separately, but it’s here now, and it will stay here :) Thank you.
      Edit: Upon re-reading my own first post on creating a development environment I found that the instructions DO state to install autoconf. Perhaps you did not start at the beginning. It has given me an idea about stating dependencies with every post. This will take some time though :)

  13. Two things I had to do:

    1) You suggest using php 5.3.15 in the beginning:
    curl –location -s http://nl3.php.net/get/php-5.3.15.tar.gz/from/nl1.php.net/mirror | tar -zx

    But later on your command line uses:
    cd /tmp/source/php-5.3.13/ext/mcrypt/

    So I edited that to use 5.13.15

    2) Your command line example assumes MAC OS 10.8 and I am on Lion (10.7):
    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=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/bin/php-config

    Also I am using just the GC compiler on it’s own so after changing the first reference to 10.8 to 10.7, I also removed the part:
    –with-php-config=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/bin/php-config

    After that it appears I have succeeded.

    Hope that helps someone else.

    -John

    1. Thanks for pointing out the 13 vs 15 typo. On your other point; perhaps you missed the “Choose OSX version” feature available in the third paragraph?

  14. After about two days of faffing about I used your instructions and they worked a treat.

    The only think I would add is that after a few botched attempts, my mcrypt versioning was giving me some grief. So I ran a ‘make clean’ in the downloaded and expanded mcrypt directory (thanks to Michael Gracie dot com) and then followed your instructions again.

    Thanks heaps

  15. I ran into some trouble with 10.8 because the latest version of xcode removed autoconf therefore removing the ability to phpize. You can follow my gist to fix that problem and get right back on track.

  16. Just a remark, if you are having an file not found error when running:
    MACOSX_DEPLOYMENT_TARGET=10.9 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=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/bin/php-config

    Make sure xcode is not upgrading because when it is it locks /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/bin/php-config

  17. I’ve tried to configure my Mac using mcrypt … the whole day. Now I found your article and i hope i’ll get through … but
    I’ve no success and the very beginning:
    sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/php /usr/include/php

    ln: /usr/include/php: No such file or directory

    1. Strange, because /usr/include/ should exist on your system already.
      see if this path exists (ls -la /usr/include)
      if not; create it; sudo mkdir /usr/include
      then try again.

  18. “You can avoid this by editing the file mentioned in the error message and replace all occurrences of PHP_FE_END with {NULL,NULL,NULL} ”

    THANK YOU!!

  19. Thank you for the guide however, I’m stuck in the installation.

    Do you have any idea why?


    michaels-mbp:mcrypt michaelsorensen$ MACOSX_DEPLOYMENT_TARGET=10.9 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=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/bin/php-config
    -bash: ./configure: No such file or directory

      1. Thanks for the quick reply.

        I’ve tried to follow step 2 and that was easy enough. Unfortunately it didn’t work.

        Tried to run “svn help” just for testing if the command tool was installed, and it was.

        This command works fine
        MACOSX_DEPLOYMENT_TARGET=10.9 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 the problem is still this command
        MACOSX_DEPLOYMENT_TARGET=10.9 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=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/bin/php-config

        I’m using php 5.4.24 there is default on my machine and not 5.4.17 as you. But I guess this should not be the problem.

  20. Hello, I’ve been trying to get this going for 2 days, but in vain:

    While Installing mcrypt at the /php-5.4.24/ext/mcrypt directory, I type phpize to give:

    PHP Api Version: 20100412
    Zend Module Api No: 20100525
    Zend Extension Api No: 220100525

    Then when I type in: MACOSX_DEPLOYMENT_TARGET=10.9 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=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/bin/php-config

    it gives:

    configure: error: Cannot find php-config. Please use –with-php-config=PATH

    and then it stops the process. Would you please advise what problem it may be? Thank you!

    1. Sorry for the delayed response; i’ve been away.
      There’s a version mismatch, are you using the instructions for your OSX version? you copied/pasted for osx Mavericks 10.9, if you are not using osx 10.9, please pick your version in the osx-version-picker. The fatal error states it cannot find the php-config file. You could issue an ‘mdfind php-config’ command to try to locate php-config. /usr/bin/php-config would be best, an Xcode-path (like in your comment) is second best and probably the only option for 10.8 and earlier. In any case, the path in your snippet is not found, so either you’re not running 10.9 or your Xcode needs to install the 10.9 support package (open Xcode to do that :) ) Good luck!

  21. Hi,

    i have php 5.5.0 when i try:

    /tmp/source/php-5.5.0/ext/mcrypt] $ phpize
    Configuring for:
    PHP Api Version: 20121113
    Zend Module Api No: 20121212
    Zend Extension Api No: 220121212
    autom4te: cannot open < /usr/local/share/autoconf/autom4te.cfg: No such file or directory

    can help me? thanks

    1. good question. First thing that hits my eye is the version-tag mismatch; your PHP version is 20121113, the zend API module and extension are 20121212. First thing you need to do is make sure you get the correct version of the software.
      About the autom4te stuff; I can’t say for sure, but I’m confident you’re missing the developer tools. You can get those from Apple dev center, or by installing XCode from the AppStore. (free)

Leave a Reply

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

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

Confidental Infomation
stop spam mail