Plugging mcrypt into PHP, on Mac OS X Snow Leopard 10.6.1

First mcrypt on Leopard, and now we ready for the winter cat. Additionally, special thanks goes out in advance to commenter Yvan Barthelemy (a.k.a. ybart) for cluing me in here. The procedure is almost exactly like the previous…almost. So pay attention.

The following instructions cater to those who a) are developing on OS X Snow Leopard 10.6.1, b) need the capabilities provided by mcrypt during their PHP development, and c) do not want to completely recompile PHP to get there. You’ll get mcrypt loading dynamically for use in PHP with this method.

First, you are going to need a few things…

1) libmcrypt-2.5.8, which you can pick up here; NOTE: make sure to get libmcrypt and not mcrypt.

2) PHP 5.3.0 source, which you grab here; and

3) Xcode 3.2 tools, which you can pick up here (Apple Developer Connection membership required).

Next, 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.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

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.0/ext/mcrypt – type…

/usr/bin/phpize (phpize should be in /usr/bin – if not go find it and change the command as appropriate)

Then configure as follows…

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

Again make -j6 then sudo make install

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 the Snow Leopard upgrade, 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

Restart Apache – you should be all set (again), according to phpinfo():

Related posts

158 comments

  1.   SanchonX comments:
       

    Thanks so much for this, very easy to follow and worked a treat!

  2.   jim comments:
       

    Perfect! Thanks so much. Worked a treat!
    Will this work for all extensions or are there some that shouldn’t be loaded dynamically?

  3.   Michael Gracie comments:
       

    Jim – I think that depends on a whole lot of factors, but I’ve been able to compile everything I ever needed. But the latest build of PHP includes quite a bit more in the way of vanilla stuff, so I think you’d have to evaluate on a case by case basis.

  4.   Donna comments:
       

    Michael, you are AWESOME! I had found some other instructions that had me dreading this process. You made it so easy. Everything worked first time just as you said. Wish I could buy you lunch; you’ve surely earned it. :)

  5.   Michael Gracie comments:
       

    Thanks for that Donna! And I’ll note I had help, and thank them again.

  6.   Martijn comments:
       

    Excellent! Finally something that worked.
    Thanks for the clear descriptions.

  7.   Derek comments:
       

    it worked like a charm… Thank you.

  8.   Bryan comments:
       

    Hmmm. Didn’t work for me. The second (mcrypt) configure ends with a notice about the ‘–with-php-config’ directive being not understood. Then the make -j6 fails with the error…

    make: *** [sapi/cli/php] Error 1
    make: *** Waiting for unfinished jobs….
    lipo: can’t open input file: /var/folders/tT/tTPfGpLBF1iLIoatrRVNC++++TI/-Tmp-//ccIMOVtx.out (No such file or directory)
    make: *** [sapi/cgi/php-cgi] Error 1

    There may or may not be related. But that;s where the trail ended for me sadly.

    Incidentally, the php-config binary is in the /Developer/… folder where it should be.

    Thanks for any help. :D

    Bryan.

  9.   Bryan comments:
       

    Oh… this is more likely the useful part of the error above…

    ld: duplicate symbol _spl_ce_SplDoublyLinkedList in ext/spl/spl_dllist.o and ext/spl/php_spl.o for architecture i386
    collect2: ld returned 1 exit status

    Bryan.

  10.   Bryan comments:
       

    Ah crap. OK. Ignore me. I’m stupid. LOL Went back and started again and this time it worked. (long story). Feel free to “reject” (moderate) all these noisy comments too btw. :P

    Bryan.

  11.   Michael Gracie comments:
       

    Rejection is not an acceptable word here Bryan. Glad it worked out for you, and hope others can learn from the (obviously) tiny mistakes that make these little tutorials so darn aggravating.

    PS: @Martijn, @Derek: You are welcome!

  12.   Luis Rosety comments:
       

    I followed your instructions but I get the following:

    checking for libmcrypt – version >= 2.5.0… no
    *** Could not run libmcrypt test program, checking why…
    *** The test program failed to compile or link. See the file config.log for the
    *** exact error that occured. This usually means LIBMCRYPT was incorrectly installed
    *** or that you have moved LIBMCRYPT since it was installed. In the latter case, you
    *** may want to edit the libmcrypt-config script: no
    configure: error: *** libmcrypt was not found

    I am starting with Mac and I have no experience with Unix nor Linux.
    Maybe I am doing something wrong…

  13.   Michael Gracie comments:
       

    Looks like you don’t have libmcrypt installed. When folks were working with Leopard, some noted similar errors and had installed mcrypt, not libmcrypt. The package you need comes from the source “libmcrypt-2.5.8.tar.gz”.

    When in doubt, delete all source and try again.

  14.   Magnus von Bromsen comments:
       

    Hello MG and thanks for a tutorial that seems easy enough even for me to follow. :)

    But, I run into a little problem: when running the first “make -j6″ I got this error:
    -bash: make: command not found

    I’m inside the libmcrypt folder when trying. Any idea how to solve that?

    Regards, Magnus

  15.   Michael Gracie comments:
       

    Hmm…path issue? Try ./make

    If that doesn’t work, try switching the shell back to default login (under preferences, if you’ve got it set to command complete path).

    Just troubleshooting ideas.

  16.   Magnus von Bromsen comments:
       

    Hi again
    I tried with “./make -j6″ but that gave me another error:
    -bash: ./make: No such file or directory

    I’m using the default login. Can this have something to do with that I got a lot of “checking … … no” when I run the first command? Like this:

    checking host system type… i686-apple-darwin10.0.0
    checking target system type… i686-apple-darwin10.0.0
    checking for a BSD-compatible install… /usr/bin/install -c
    checking whether build environment is sane… yes
    checking for gawk… no
    checking for mawk… no
    checking for nawk… no
    checking for awk… awk
    checking whether make sets $(MAKE)… no
    checking whether to enable maintainer-specific portions of Makefiles… no
    checking whether make sets $(MAKE)… (cached) no
    checking for g++… no
    checking for c++… no
    checking for gpp… no
    checking for aCC… no
    checking for CC… no
    checking for cxx… no
    checking for cc++… no
    checking for cl… no
    checking for FCC… no
    checking for KCC… no
    checking for RCC… no
    checking for xlC_r… no
    checking for xlC… no
    checking for C++ compiler default output file name… configure: error: C++ compiler cannot create executables
    See `config.log’ for more details.

    Regards, Magnus

  17.   Magnus von Bromsen comments:
       

    Sorry!

    I just found out that I had only Xcode 3.1.2 (I was absolutly sure that I had 3.2). I will come back after I tried it with the right version.

    Sorry :(

    – magnus

  18.   Michael Gracie comments:
       

    Magnus – the XCode version shouldn’t have made that much of a difference, but from the looks of the above I would have guessed you didn’t have the developer tools installed at all.

  19.   Magnus von Bromsen comments:
       

    I’m so stupid!
    Everything solved after updating Xcode :)

    Really sorry.

    Regards, Magnus

  20.   Magnus von Bromsen comments:
       

    Well, maybe it was I had an updated SL (from Leopard). Some setting was wrong or missing…

    But, now I’m happy :)
    And many, many thanks for this guide (now I can install Magento 1.4 for testing).

    magnus

  21.   Michael Gracie comments:
       

    I take that back. The old Xcode wouldn’t have had the 10.6 dev environment.

  22.   Paul Dobbertin comments:
       

    Thanks so much for the great tutorial. This worked like a charm.

  23.   Muhammad Hirman comments:
       

    This helped. Thanks! :)

  24.   Michael Gracie comments:
       

    @Paul/Muhammad – No prob. Glad it worked out for you.

  25.   Jason comments:
       

    Thanks for the walk-through – works great! I got the same error as Luis Rosety’s error, btw. The reason is exactly as you said, however what you were saying wasn’t registering at first. The download link provided for libmcrypt has source for both mcrypt and libmcrypt. The highlighted download at the top of that page is for mcrypt, though. You have to look below to fine the libmcrypt source. It would have helped me if you put a little note next to that step that says “make sure to get libmcrypt and not mcrypt!” I know it’s a silly mistake, but that download page makes it appear that you should be downloading mcrypt.

  26.   Installing LAMP stack on OSX 10.6 Snow Leopard « VerySimple, Inc. pings back:
       

    [...] everything that I need except mcrypt.  Luckily Michael Gracie has provided a walk-through for installing mcrypt on Snow Leopard which involves re-compiling some things, but isn’t as tough as it first [...]

  27.   David comments:
       

    As others have stated, the steps are very clear, and worked the first time through flawless. Thank you for taking the time to write this up.

  28.   billd comments:
       

    perfecto! thanks

  29.   crucco comments:
       

    Hi, that was a nice try like all other advices on the web. I was too new with 10.6.2 everything seemed to work out fine. But now PHP isn’t working anymore….

  30.   Michael Gracie comments:
       

    crucco – Do you mean Apache won’t start?

  31.   crucco comments:
       

    it means that its impossible to create a php.ini file instead of php.default.ini and make that timezone-warnings pass because
    on 10.6.2 php refuses to run with php.ini file. it works only on php.default.ini and you can’t change anything because all remains default.. apple developers change to much on that and without any clue what serves web-developers … grmpfff

  32.   Michael Gracie comments:
       

    crucco – PHP is still the same build, 5.3.0, on 10.6.2. I’ve done the update, and everything is still working fine (including the mcrypt). Are you certain you don’t have a permissions issue?

    UPDATE: I just checked my install, logged in as root. I have php.ini and php.ini.default, and full control over them. Just for shits and giggles, I bak-ed the ini file, copied and renamed php.ini.default (to php.ini), added the extension reference, and restarted Apache without issue.

  33.   crucco comments:
       

    Hi Michael,
    was thinking about rights. checked all and changed it php.ini’s owner is root and the group is wheel. repaired all rghts with disk utility booting off a cloned system, tried everything. But, when there is a php.ini phpinfo won’t show anything and php doesn’t work. when php.ini is deleted and ther’s only the php.default.ini everything works. but also if you set the date_timezone in that file all remians defult. So the only clue for me now is that is has something to with 10.6.2 snow leopard update. I can’t tell what was before because I started a fresh install with that update.

  34.   Magnus von Bromsen comments:
       

    @crucco

    I’m afraid that I don’t have a solution for you. But I also have 10.6.2 – and I *think* that’s working all right (at least, the info.php seems right).

    – magnus

  35.   Michael Gracie comments:
       

    @crucco – a quirk I noticed…

    You say you have php.ini and PHP.DEFAULT.INI, but on two machines I have php.ini and PHP.INI.DEFAULT. See the difference? Maybe there is a conflict there.

    Have you tried deleting php.ini, duplicating and then renaming your PHP.DEFAULT.INI to php.ini, and restarting? Try without the other ini file in there.

    Again, this doesn’t seem like 10.6.2 issue, at least not to me (or MvB).

  36.   Jared Howard comments:
       

    I was going nuts trying to figure out why this wasn’t working for me. Everything looked like it worked correctly until I restarted Apache and my phpinfo page wouldn’t pull up. I noticed that I could have a blank php.ini and restart Apache and it would pull up just fine. It took me awhile but I noticed that by default short_open_tag=Off. Well out of habit I use <? instead of <?php. Once I turned short_open_tag=On, it all worked for me with mcrypt installed. Thanks.

  37.   crucco comments:
       

    @michael

    excuse me if I’m wasn’t precise enough. The filenames are as you told: php.ini and php.ini.default. maybe it depends also on the newest xcode321_10m2003_developerdvd.dmg I used to install xcode-tools. The strange thing to me is that it was a clean install on a fresh formatted disk with snow leopard from Mac Box Set and the 10.6.2 Combo-Update. That was all I made: install, update, install xcode. made php.ini from php.ini.default changed only the one line with the ;date.timzone= to ‘date.timezone=Europe/Berlin’ started the Webservice with httpd.conf LoadModule php5 without #. PHP works when there’s no php.ini. The Timzone-error remains on phpMyAdmin. All the rest is fine….cloned the System with superduper to a firewire-disk tried to boot instead on MacBook Pro on an iMac. The problem persists.

  38.   Michael Gracie comments:
       

    crucco – I’m at a loss, particular since I don’t really know what effect date.timezone would have on mcrypt. The only thing I can suggest is cleaning out the source and starting over. Sorry.

  39.   crucco comments:
       

    did a clean reinstall on another harddisk with snow leopard created a php.ini from default, activated php in httpd.conf – same thing again.
    are there any apple specialists around who can explain that to me? on the whole internet there’s no discussion of that phenomenon….

  40.   Travis comments:
       

    Thanks so much for the tutorial — worked like a charm!

  41.   crucco comments:
       

    found the error: I have tu use instead of the short form . Now the PHP-Info gives the right
    output. If one uses the short form on mac you get a blank page with no error message. How dumb I was….

  42.   Michael Gracie comments:
       

    crucco – Glad you got it working. Jared Howard (above) had a similar problem. Not dumb…just technology!

  43.   Stephen comments:
       

    I get to the point where I ./configure php. But I end up with
    Notice: Following unknown configure options were used:
    –with-php-config=/Developer/SDKs/MacOSX10.6.sdk/usr/bin/php-config
    Check ‘./configure –help’ for available options

    when I do check for available options I don’t see an option like –with-php-config.
    I noticed that Bryan had the same problem with mcrypt. Unfortunately he didn’t say
    what he was doing wrong.
    Any idea where to start looking is welcomed.

  44.   Michael Gracie comments:
       

    Stephen – Do you have the latest developer tools installed (in other words, does /Developer/SDKs/MacOSX10.6.sdk exist)?

  45.   Stephen comments:
       

    Yes, both ( OSX 10.6 and Xcode 3.2 ) from the SL DVD. One thing I forgot to mention was that I did a clean install of 10.6.
    Not an update over my old 10.5. I noticed with other tools that they needed some tweaking to work again ( AVR compiler
    tool chain needed other compiler settings ).

  46.   Michael Gracie comments:
       

    Stephen – Without a machine I can try doing a clean install on, all I can suggest is deleting all source, making sure the existing install of PHP is the same version as the source you downloaded, unwrapping everything and trying again.

  47.   Michael Kaiser comments:
       

    Hi Michael,
    thanks a lot for your tutorial. I never would find this out by myself.
    I have a little problem while installing the PHP extension from ext/mcrypt. The configure command starts, checks some things and then stops with the following error:

    checking for MSSQL support via FreeTDS… yes, shared
    configure: error: Cannot find FreeTDS in known installation directories

    No makefile is generated.

    Any suggestions…?
    System: 10.6.2 Server (german)

  48.   Michael Kaiser comments:
       

    Problem solved. After downloading PHP 5.3.0 from Apples Open Source Server the installation worked without a problem.

  49.   Jesse comments:
       

    Hi Michael,

    Your tutorial has helped me a lot.

    While I can run through these steps on one machine what I really need is something I can plug into my software installation process (I develop some software that depends on the mcrypt PHP extension).

    Is it enough, after building the PHP extension to just copy this into the extension folder and setup the php.ini settings appropriately or do I need to do some other steps to get libmcrypt installed up first?

    Thanks,
    Jesse

  50.   Michael Gracie comments:
       

    Jesse – You could do that, assuming all the operating environments are the same. Unfortunately, the moment they differ or something gets upgraded, like PHP itself (which happens occasionally with OS X updates) you’re toast.

    My suggestion would be to write a script (maybe use Perl) which would check PHP versions, check for libmcrypt existence, grab all the relevant source code, and does the compilation and various mods for you.

  51.   Jesse comments:
       

    Thank Michael.

    Can I get away with just installing the extension “mycrpt.so” or do I need to plug in all the other executables that are created and installed during the libmcrypt steps above as well.

    In other words does mycrypt.so stand by itself after all the steps above are done or does it in fact depend on the libmcrypt executables them selves also being loaded on the system.

    Jesse

  52.   Michael Gracie comments:
       

    It should stand alone (but that does assume the environments are identical).

  53.   Chris Stetson comments:
       

    Just as a note, you need to use Bash in order to get the commands to work correctly. I prefer tcsh (legacy reasons) and the environment variables don’t work. Once I switched to Bash, things went much more smoothly.

  54.   Chris comments:
       

    Thanks so much! :) … it works great

    very clearly, precise and easy to understand tutorial, thanks again for sharing this!

  55.   Kenny comments:
       

    Michael,

    Thanks a bunch for the tutorial! It’s definitely one of the better ones that I’ve seen. Unfortunately I’m still having issues getting the mcrypt extension working. I’ve gone through this tutorial 2 times already, each time wiping the source (in SourceCache). But PHP is still not recognizing mcrypt. Could the problem possibly be with my configuration of PHP?

    Many thanks!

  56.   bveale comments:
       

    Super tutorial, thank you so much…

  57.   Michael Gracie comments:
       

    @Kenny – Shouldn’t be, but wondering…have you done your own PHP compilation?

    @bveale – You’re welcome!

  58.   Kenny comments:
       

    @Michael

    No, I enabled the built in PHP via uncommenting line115 in the httpd.conf file.

  59.   Michael Gracie comments:
       

    Ok. I’m assuming PHP is running, and that the compiles worked without error. Dynamic loading enabled, and you have extension=mcrypt.so on a line under dynamic extensions?

    Also, search for mcrypt.so, and post where you found it. If you found it.

  60.   Kenny comments:
       

    My mcrypt.so file is located in /usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so

  61.   Michael Gracie comments:
       

    Kenny – it is in the right place for certain. Hope you can wait a few day to see if someone comes along and has the same problem plus the solution. The only thing I can think of is clear the browser cache, because right now it should be running. Sorry I can’t be of more help at the moment :-(

  62.   Nick Merritt comments:
       

    This was just straight-up helpful and your assistance was very much appreciated. Thanks for putting me one step to closer to command-line fearlessness. and Happy holidays!

  63.   Paul comments:
       

    Hi, This worked fine for me until the rename php.ini.default to php.ini bit. If I do this and try and run phpmyadmin I get the following error
    “#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)” I can change back to php.ini.default and phpmyadmin works fine but phpinfo doesn’t show mcrypt anymore(it does if I use php.ini). Any idea’s?

  64.   Michael Gracie comments:
       

    Paul -

    Do other PHP applications work when php.ini is in place? I’m not familiar with phpmyadmin settings, but it might be a simple matter of it looking for php.ini.default – can you change it to look for php.ini? Also might make sense to just copy the default file as php.ini, leaving the original file intact.

  65.   Paul comments:
       

    No, another php app also stopped working (couldn’t connect to mysql) I had tried having both the php.ini file and the php.ini.default in place but this made no difference. phpmyadmin doesn’t seem to have any setting as to looking for the php.ini file. Thanks for taking the time to reply. It’s not a big deal as it’s only a development machine, mcrypt is working fine on my webserver.

  66.   Dale comments:
       

    I need to get 10.6 PHP fixed and to understand the PHP plugin process. I can’t believe this is such a pain. In you instruction am I going to be replacing the stock PHP? or just using the source to do the builds? I might give this a try

    thanks

    -dale

  67.   Michael Gracie comments:
       

    “just using the source to do the builds”

  68.   Sebastian comments:
       

    You were so helpful to me! Thanks a lot!

  69.   Freedom OSS comments:
       

    Thanks mate! It works fine. I can use now my phpMyAdmin without giving me the nuisance error for mcrypt.

    More power to you!!!

  70.   Roger Creagh comments:
       

    Another vote of thanks for some very clear and easy to follow instructions with just enough explanation to help one understand what is going on and needs to be done. Worked exactly as stated on the tin.
    Many thanks.

  71.   ThinkMud comments:
       

    @Paul did you fix your #2002 error with mysql? I’m getting the same think:(

  72.   ThinkMud comments:
       

    @Paul actually I found a fix for the MySQL #2002 error in phpmyadmin, I had to change config.inc.php from using “localhost” to “127.0.0.1″ in this line:

    old:
    $cfg['Servers'][$i]['host'] = ‘localhost’;
    new:
    $cfg['Servers'][$i]['host'] = ’127.0.0.1′;

    hope that helps.

  73.   Paul comments:
       

    Thanks ThinkMud that worked. Had to change my php apps from localhost to 127.0.0.1 for them to work also.
    Cheers

  74.   ThinkMud comments:
       

    There has to be something we can set somewhere for MySQL to make localhost point to 127.0.0.1, you know? like the hosts file is already set up to do that, wonder why MySQL doesn’t do it? I’ll keep searching b/c I hate to have change all my config files to point to 127.0.0.1 instead of locahost because all my live sites have localhost. I’ll dig around more tomorrow and figure it out:)

  75.   EpiDot comments:
       

    I am just one more who is very grateful for this information! Thanks a lot!!

  76.   phpMyAdmin – Installing LAMP/MAMP on Snow Leopard/Mac Pro Part II « NIM ReFLEXtions pings back:
       

    [...] the following site which has instructions on plugging the mcrypt module into php on Snow Leopard: Plugging mcrypt into PHP, on Mac OS X Snow Leopard 10.6.1 which was a godsend. It worked out of the box for me. I believe it makes(compiles) the mcrypt.so [...]

  77.   Turborob comments:
       

    Just one more confirmation regarding Chris Stetson’s comment that some of the commands need to be done in Bash. Specifically, the configure of the PHP mcrypt failed on my system as unable to determine the version of libmcrypt. Once I did everything as sudo -s, it worked fine. Next problem I had was following some other instructions to place my php.ini file in /etc/apache2, but PHP was looking for it under /etc (logically where the default file is already located). Works great now and thanks for the tutorial!

  78.   Brent comments:
       

    @Michael Gracie – Thank you, thank you! Its been a long day and this finally was something that went right.

    @ThinkMud and @Paul – I solved the error (the 127.0.0.1 issue) with phpMyAdmin by changing “/var/mysql/mysql.sock” to “/tmp/mysql.sock” everywhere in the php.ini file and then restarted the web server. I’m not sure why that works.
    I found it at: http://maestric.com/doc/mac/apache_php_mysql_snow_leopard

  79.   Michael Gracie comments:
       

    You are definitely welcome Brent.

  80.   ThinkMud comments:
       

    @Brent Thanks dude! seems to work good now.

    @Micheal Gracie – Thanks for the write up, this is awesome. I’m the type of guy that always has to have a local set up to match my live sites so I can fully test locally and not break the live sites. This has saved me lots of time. Thanks again!

  81.   Mike Kormendy comments:
       

    Wanted to say thanks for writing this up, I had managed to perform this installation first, and then upgraded the GD package to include FreeType as documented here:

    http://www.gen-x-design.com/archives/recompiling-php-5-3-on-snow-leopard-with-freetype-support/

    (Be sure to look for my comments that have fixes to some of the recompile process)

    Was glad that the recompile of PHP for GD did not affect mcrpyt.

    Cheers!

  82.   Mark comments:
       

    Micheal thanks much for writing this up. Saved me a bunch of time fishing for answers.

  83.   rezorte comments:
       

    Great thanks!!!

  84.   Laura Landy comments:
       

    Thanks for this info.

    I’ve gotten this far:

    Move back to /SourceCache, then down to php-5.3.0/ext/mcrypt – type…

    /usr/bin/phpize (phpize should be in /usr/bin – if not go find it and change the command as appropriate)

    Then configure as follows…

    Confused. phpize is not a directory. Do I just go to /usr/bin and configure? {note: I already had PHP5 installed.]

    Thanks!

  85.   Michael Gracie comments:
       

    Laura –

    phpize is an executable – you are not going in there, you are just typing the command ‘/usr/bin/phpize’ to run it. If it’s not in /usr/bin/ you have to go find where it is, and run with it’s correct path.

  86.   Laura Landy comments:
       

    Michael, thanks for the info, and I still don’t get it. Because I already had PHP installed, I didn’t create the SourceCache dir.
    I am typing usr/bin/phpize at the prompt
    but get the response: usr/bin/phpize: No such file or directory.
    Yet when I list the files in usr/bin the phpize is there:

    laura-landys-macbook-pro:/ lauralandy-PB4$ cd /usr/local/php5
    laura-landys-macbook-pro:php5 lauralandy-PB4$ ls -l
    total 89336
    drwxr-xr-x 9 root wheel 306 Mar 26 2009 bin
    -rw-r–r– 1 root wheel 440 Mar 26 2009 entropy-php.conf
    drwxr-xr-x 7 root wheel 238 Jan 24 18:29 etc
    drwxr-xr-x 3 root wheel 102 Mar 26 2009 include
    drwxr-xr-x 62 root wheel 2108 Jan 24 18:29 lib
    -rwxr-xr-x 1 root wheel 45732808 Mar 26 2009 libphp5.so
    drwxr-xr-x 14 root wheel 476 Jan 24 18:29 php.d
    drwxr-xr-x 4 root wheel 136 Jan 24 18:29 share

    laura-landys-macbook-pro:php5 lauralandy-PB4$ cd bin
    laura-landys-macbook-pro:bin lauralandy-PB4$ ls -l
    total 87848
    -rw-r–r– 1 root wheel 1973 Mar 26 2009 activate-entropy-php.py
    -rwxr-xr-x 1 root wheel 824 Mar 26 2009 pear
    -rwxr-xr-x 1 root wheel 845 Mar 26 2009 peardev
    -rwxr-xr-x 1 root wheel 761 Mar 26 2009 pecl
    -rwxr-xr-x 1 root wheel 44949320 Mar 26 2009 php
    -rwxr-xr-x 1 root wheel 3726 Mar 26 2009 php-config
    -rwxr-xr-x 1 root wheel 4198 Mar 26 2009 phpize
    laura-landys-macbook-pro:bin lauralandy-PB4$

    I am very new to using terminal so I am probably missing something very basic.

    I appreciate your help, thanks!

    Laura

  87.   Michael Gracie comments:
       

    Laura –

    Because I already had PHP installed, I didn’t create the SourceCache dir.

    You must grab the PHP source code for your version of PHP, and follow the directions exactly as prescribed above. Most if not all users of these instructions already have PHP installed – you need that source code to create the mcrypt plugin.

    Again, there are no shortcuts – follow the instructions to the letter. UPDATE: you can’t type “usr/bin/phpize” – you must type “/usr/bin/phpize”

  88.   Laura Landy comments:
       

    Thanks, Michael. After many hours of fighting, I just installed MAMP, so I guess I took a short cut ;}

  89.   Frank Indelicato comments:
       

    Thank you Michael, your advice worked without a flaw…good luck merging the fly-fishing….

  90.   Maryann comments:
       

    I did the install and it all went well, but when I restart apache, mcrypt does not show in the phpinfo page – is the only file snow leopard reads php.ini? It seems like it’s not picking up any changes in the php.ini file.

  91.   Michael Gracie comments:
       

    @Maryann – I’m assuming “all went well” means compile completed without errors. Check to make sure that mycrypt.so is in /usr/lib/php/extensions/no-debug-non-zts-20090626/, that it is properly linked per the instructions, and that dynamic linking is enabled.

  92.   Maryann comments:
       

    yes, that’s what I meant – no errors, I ran it again to be sure it went without error. mycript is the right place, I setup the linking – how do I check that dynamic linking is enabled? It just seems like apache is NOT reading the php.ini file – does snow leopard read an alternate php.ini file somewhere other than /etc/php.ini? Thanks for responding, I really appreciate it!!

  93.   Michael Gracie comments:
       

    From above -

    Ensure that enable_dl = On but do not remove the ; from in front of ;extension_dir = “./”

    Apache shouldn’t be looking at anything else (assuming PHP is running, and you are using the out-of-box version), but that’s up to httpd.conf. I’d starting looking through phpinfo() results next.

    This is probably going to wind up being a minuscule detail, which is always the worst part of debugging.

  94.   dd comments:
       

    Big thanx man !!. All worked well. Thx again.

  95.   erinol comments:
       

    @Maryann – I also had a problem with mcrypt not working, but compiling and installing fine. It turned out that it wasn’t reading my php.ini file. run phpinfo and check the “Loaded Configuration File” Value (it said not read for me). Once I fixed that, everything was fine.

    Thanks Mike!

  96.   Maryann comments:
       

    I got it all working, worked great! (finally!)

  97.   Dani comments:
       

    I am just learning all this please explain this part

    Move back to /SourceCache, then down to php-5.3.0/ext/mcrypt – type

    /usr/bin/phpize (phpize should be in /usr/bin if not go find it and change the command as appropriate)

  98.   Joel comments:
       

    Hey Michael – appreciate the guide. Have done this on a couple of my machines to get up and going and had great success. Ran into an issue on my last machine however. When I run /usr/bin/phpize, I get the error: “Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module” I’ve looked online but not had any luck tracking down how to fix this. Any ideas?

  99.   John comments:
       

    I ran into trouble when executing “make -j6″ in the libmcrypt directory. I get the error:

    ld: symbol(s) not found for architecture x86_64
    collect2: ld returned 1 exit status
    lipo: can’t open input file: /var/folders/fR/fRJnS6VWGW0QaiJPjG-P4k+++TI/-Tmp-//cc6Jdq6z.out (No such file or directory)

  100.   John comments:
       

    Mea culpa. I had the production version of libmcrypt. Once I trashed that and downloaded version 2.5.8, life became happy.

    I thought I was being cautious when I used production, but I was just being wrong.

  101.   albert comments:
       

    Big thanks to michael mcrypt works now after long search in internet. Great work and easy to install.

  102.   Hans comments:
       

    @Joel: I ran into the same problem and found a solution here: http://discussions.apple.com/thread.jspa?threadID=2219620&tstart=0

    Go into cd /SourceCache/php-5.3.0/ext/mcrypt before you run phpize.

    HTH

  103.   Mario comments:
       

    Wish I had an idea of all I’ve just done :-)
    Thank you.

    Just a note on the download of the libmcrypt, like somebody else already said, the link provided takes to a file that says it has both files (mcrypt and libmcrypt) together, but I couldn’t get the libmcrypt alone… so I found it somewhere else (linux.softpedia.com to be exact) and worked with that file.

    Maybe the mcrypt file provided worked, but since you made a point out of getting libmcrypt alone..

    Again, thank you!

  104.   Svish comments:
       

    Thanks! Worked flawlessly on first try =)

  105.   Nancy comments:
       

    Fantastic! Worked like a charm – even for a novise like me!

  106.   Rémi comments:
       

    nice tutorial. Thank you !

  107.   Sam Critchley comments:
       

    Thanks Michael. This worked a treat for me – I already had XCode installed so just needed the two other downloads. I lost phpMyAdmin after upgrading to 64-bit MySQL in Snow Leopard and this fixed the problem.

  108.   Sam Critchley comments:
       

    PS One more thing. For less Unix-familiar users, you can use the following two commands for path etc on most systems:

    1. “which xxxx” – where xxxxx=name of other command. It will come back with the location of the executable for that command. For example, typing “which phpize” will usually give you “/usr/bin/phpize” back.

    2. “pwd” – this tells you the path to the directory you are currently in.

  109.   Sebastian comments:
       

    Greets from Berlin, Germany.

    Thanks for the great tutorial. In the first try forgot the step where you call /usr/bin/phpize and got the same errors as Bryan, but then it worked out great.

  110.   Michael comments:
       

    Worked perfectly. Cheers.

  111.   Ess comments:
       

    Excellent

    Thank you very much.

  112.   Reda comments:
       

    Thanxs ! This tutorial is awesome !

  113.   k00k comments:
       

    Oh Man, this worked wonders. Thanks a billion! I was struggling with Snow Leopard’s lack of mcrypt.

  114.   Ross comments:
       

    Thank you sir. Excellent work.

  115.   Ward comments:
       

    Thanks for the tutorial, seems to have helped alot of people. Not working for me though. I’m on a 13″ macbook i bought in February 2010. Turned on web sharing. Enabled php just fine. Installed mySql and phpMyAdmin just fine. However when trying to login to phpMyAdmin i get the mcrypt not installed error. :) So on I went, three tutorials later I am at your page and this is looking good. Followed the instructions. Get to this point:

    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

    and I get the

    configure: error: Sorry, I was not able to diagnose which libmcrypt version you have installed.

    Someone mentioned running locate mcrypt? I get this:

    bash-3.2# locate mcrypt
    /private/var/db/receipts/ch.entropy.php.mcrypt.bom
    /private/var/db/receipts/ch.entropy.php.mcrypt.plist
    /usr/local/bin/libmcrypt-config
    /usr/local/include/mcrypt.h
    /usr/local/include/mutils/mcrypt.h
    /usr/local/lib/libmcrypt
    /usr/local/lib/libmcrypt.4.4.8.dylib
    /usr/local/lib/libmcrypt.4.dylib
    /usr/local/lib/libmcrypt.dylib
    /usr/local/lib/libmcrypt.la
    /usr/local/man/man3/mcrypt.3
    /usr/local/share/aclocal/libmcrypt.m4
    /usr/share/file/magic/mcrypt

    Should i just start over? Find some tutorials on uninstalling php? Mysql?

    :/

    Thanks for any help

  116.   Yaniv comments:
       

    Michael, Bryan,

    I’m puzzled. In the source code of PHP 5.3.0 (and .1 and .2) there’s no –with-php-config option to the ./configure script. When I run it, I get the warning message that Bryan mentioned in his comment of October 21. The referenced file (in /Developer/…) does indeed exist.

  117.   G.Dubya comments:
       

    Brilliant! Worked exactly as stated with 10.6.3, MySQL 5.1.46, and PHP 5.3.1.

    So grateful that you published this!

  118.   Chris comments:
       

    Hey Michael! Thanks very much for this tutorial; works great!!

  119.   Jonathan comments:
       

    Fantastic guide, Michael. This was quick and painless on OS X 10.6.2/PHP 5.3.0

  120.   joan comments:
       

    Fantastic tutorial, it also works wiht the 5.3.1 php

    thank you so much…

  121.   Mac OS X Snow Leopard missing mcrypt for PHP pings back:
       

    [...] about was that libmcrypt was missing. After a few web searches, found this helpful info from Michael Gracie. First, you are going to need a few [...]

  122.   Papang comments:
       

    Thank you very much for this tutorial. It works very well.
    Merci beaucoup pour ce tutorial. Ca marche à merveille.

  123.   Mat comments:
       

    Hi, sorry – when you say create a new directory at root is that in the library / webserver / documents directory or in the mac system root – if so do I have to do anything to reveal the root dir of the mac os?

  124.   Michael Gracie comments:
       

    @Mat – System root, which can be at your admin user. So, at /Macintosh_HD will do.

  125.   Ben Jamieson comments:
       

    A hundred and twelve thankyou’s!

    I found your awesome tutorial after a struggling with a different one for two hours.

    Yours: 5 minutes and done!

  126.   Mat comments:
       

    Sorry for my naivety …where do I find the directory /etc

  127.   Michael Gracie comments:
       

    It’s under root.

  128.   Mat comments:
       

    Does this /etc folder exist by default, or is it added as a result of the process as above?

  129.   Michael Gracie comments:
       

    By default.

  130.   Mat comments:
       

    OK the etc folder is within the “private” folder (which as far as I am aware isn’t visible under the file system as standard, I found it using the web browser and typing /etc/ into the address bar) under root as you said. I feel like I am being taught a lesson here (for my good perhaps). None the less, I did persevere and I have got mcrypt working – so many thanks. …if I can do it – anyone can!

  131.   Hormoz comments:
       

    i encountered a problem. after runnig the first command when i entered “make -j6″ it said : “make: *** No targets specified and no makefile found. Stop.”
    now i know i should specify a file or something, but what should i specify ?

  132.   Michael Gracie comments:
       

    The instructions are intended to work exactly as stated. Could be wrong directory, or wrong source code download.

  133.   Hormoz comments:
       

    yep, it was a minor mistake from my side. tnx for this guide.

  134.   Luis comments:
       

    It worked!
    It’s easy, as you mentioned.
    So now it’s loaded as a dynamic module. Never tried that, because I am always working in Linux, compiled, and so on.
    Now trying to recreate a working machine at home.
    To access root directory, in case somebody has problems locating it, in my machine, a normal MBP, type in terminal:
    sudo cd /private/var/root
    and then the root password.

    Thanks a lot.

  135.   Thomas comments:
       

    Thanks for that – very useful.

    I found that if you have white space in your ‘cache’ folder name, the process doesn’t run properly. As ever, always follow the instructions!

  136.   kiran comments:
       

    i am getting the following error after running ‘make -j6′ while installing libmcrypt :

    make all-recursive
    Making all in modules
    make[2]: *** No rule to make target `all’. Stop.
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2

    please help..

  137.   Michael Gracie comments:
       

    Kiran – Could be wrong source, wrong directory…even a typing error.

    Best suggestion…start over.

  138.   kiran comments:
       

    i dont know how, i started all over again with the same files and everything works just fine… thanks a lot

  139.   stooky comments:
       

    hi michael

    some questions please:

    if I do understand you right, this method installs libmcrypt and injects it to the existing installed php?!

    a) will it work on a preinstalled php 5.3.2 as well? have a new mac and php 5.3.2 is installed and running.
    b) create directory at root you mean / not /private/var/root
    c) after all the process if mcrypt is propperly showing up in phpinfo, the source cache can be deleted? (if we need this just for injection into existing php installation it should be obsolete after success).

    thc and rgds,
    stooky

  140.   Michael Gracie comments:
       

    a) it should
    b) yep, root, like /Macintosh HD
    c) yes

  141.   stooky comments:
       

    cheers michael

    worked smothly on
    macbook with php 5.3.1
    macmini with php 5.3.2

    rgds,
    stooky

  142.   Aziwaan comments:
       

    Hi Michael,

    I have followed your instructions to the T, everything through terminal worked with no errors however when I run php.info i cant see mcrypt. Ive restarted websharing but still no joy.

    Any suggestions??

    cheers in advance.

    aziwaan

  143.   Michael Gracie comments:
       

    Could be php.ini, which I’d double check first. With no way to replicate/debug I’d delete all the files and start from scratch.

  144.   Aziwaan comments:
       

    Scratch that last one, I kooked it, had extension=mcrypt.so commented out in php.ini : (

    Thanks again.

  145.   David comments:
       

    Thanks for this, it finally got mcrypt working for me after a few attempts following other guides. Just something I came across when I did it and in relation to Brent’s comment on January 18th (I wanted to make sure nobody had posted this fix already), if you don’t already have a php.ini and you copy the php.ini.default to create one, there is a bug in OS X in that the php.ini.default file has the location of your mysql socket as being at /var/mysql/mysql.sock. However, if you have installed mysql from scratch, the default location for it (and maybe this is just a 10.6 thing, it may be somewhere different on Leopard and earlier) is at /tmp/mysql.sock. That’s why Brent’s fix worked. A slightly more reliable way to fix the issue is simply to comment out the line that declares the mysql.sock location and your system will search for and find it.

    In short, the issue Brent had is simply bad configuration in Snow Leopard…

  146.   Illogical Ordering » MySQL socket problem on Snow Leopard pings back:
       

    [...] so you’re in reasonably safe hands).  After following the tutorial on installing mcrypt from here I started getting an error connecting to the mysql server I have running on my development system. [...]

  147.   Doctor Sushi comments:
       

    Just used your instructions on OS X Server 10.6.3, with the PHP 5.3.1 source. Worked perfectly.
    Thanks for the excellent walk-through, you just saved me countless hours.

  148.   NightFury comments:
       

    Kudos! – This worked wonderfully!

  149.   m7o comments:
       

    I would also like to say Thanks A Lot!

    For all who are not so familar with the terminal (like me): Make sure you are working from the “bash” shell. You can set this in Terminal -> Preferences. In my case the shell was tcsh, probably because I use the same User since the very first days of OS X. And in the tcsh shell the commands won’t work (different syntax).

  150.   m7o comments:
       

    I just saw that somebody already mentioned the tcsh thing… sorry

  151.   nottinhill comments:
       

    The trick by david with the mysql socket locatioin did it for me. Excellent! I wrapped this into my own tutorial about how to install magento on Unix: http://meshfields.de/install-magento-on-unix/

  152.   flexliv comments:
       

    Worked like magic. I used this for phpMyAdmin after installing mysql.
    Great tutorial.

  153.   Michael Gracie comments:
       

    Excellent!

  154.   Installing LAMP stack on OSX 10.6 Snow Leopard | VerySimple pings back:
       

    [...] everything that I need except mcrypt.  Luckily Michael Gracie has provided a walk-through for installing mcrypt on Snow Leopard which involves re-compiling some things, but isn’t as tough as it first [...]

  155.   Michael Johnston comments:
       

    Thank you!!!

  156.   Chris comments:
       

    Okay, so i’ve been struggling with this issue for some time now and have now come across your page: I have the libmcrypt-2.5.8, also the new PHP 5.3.3. However when going through the first step(typing in “MACOSX_DEPLOYMENT_TARGET=10.6…”) i’m running into what seems to be a trivial but yet bothersome error. It returns the error:

    “checking build system type… /bin/sh: ./config.guess: No such file or directory
    configure: error: cannot guess build type; you must specify one”

    I have no idea why it couldn’t use / find the guess.config. So far i have been really stuck at this point….I have Apache 64-bit, MySQL-64-bit, and currently php5.3.1 64-bit installed(without mcrypt), but would like to switch to newer version(5.3.3) also(which means uninstallation of current and probably build new one). This one error is stopping the mcrypt installation which i need for phpMyAdmin. Any suggestions about this issue?

    Also, i have tried a MacPorts install for mcrypt and it seems to have a compiled 64-bit unix executable version of mcrypt that was generated, however that’s not being recognized by the php and i’m not sure how i might just use the unix executable file from the MacPorts build and add it as a php module( if that is even possible).

  157.   Michael Gracie comments:
       

    Chris -

    It seems you may be using the wrong source – if you have 5.3.1 installed, you must use the 5.3.1 source (not 5.3.3). That’s all I can guess, as you’ve got so many moving parts engaged.

  158.   Chris comments:
       

    Hi Michael…

    It turns out it was obviously a silly error on my part. What i meant to say was that i was in the libmcrypt-2.5.8 and using the corresponding flag options the (MACOSX_DEPLOYMENT_TARGET=10.6…) part, when it was returning the error i stated. So i just skipped that module and tried installing others which seemed to work fine, because once i got the xdebug module working, i tried at the libmcrypt again, but this time re-downloading and unpacking it. It turns out that the original libmcrypt downloaded with an error, didn’t unstuff correctly and therefore the associated folders that were needed weren’t there, which explains the error…

    Also i notice with some websites when setting the flag options for the configure(libmcrypt-2.5.8) they have:
    1 ) ./configure –disable-posix-threads –enable-static

    and using your options we have the:
    2)
    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

    Is there a notable difference between the two options or are they relatively going to function the same way?

Leave a comment