Craig Waterman | Technologist, Software Engineer | Syracuse, NY
  • Facebook
  • Twitter
  • Home
  • Portfolio
  • Contact Me

Adding mcrypt as an extension to PHP on OS X 10.7 (Lion)

Posted on July 21, 2011 by craig in PHP, Programming
Home» Programming » PHP » Adding mcrypt as an extension to PHP on OS X 10.7 (Lion)

This is a guide for those who need to install (or re-install) mcrypt under PHP in OS X 10.7 (Lion).

You’ll need the following:

  • PHP Source Code—Lion seems to ship with 5.3.6, you can get that here. You should double-check your version with phpinfo() just in case.
  • libmcrypt 2.5.8 (yes, it really is from 2007). that’s here. I grabbed the bz2 version.
  • Xcode 4.1 – supported on Lion; it’s available on the Mac App Store. You’ll still need an Apple Developer account to download the post-install updates.
  • A place to uncompress and compile everything, move your php and libmcrypt downloads here.
    • I usually use a directory in under my home named Source. In this case, I’m putting everything in a Lion specific folder: /Users/sushi/Source/lion/
Now we need to uncompress our sources:
cd ~/Source/lion
tar xvfj libmcrypt-2.5.8.tar.bz2
tar xvfz php-5.3.6.tar.gz
Let’s configure libmcrypt for installation:
cd libmcrypt-2.5.8
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \
LDFLAGS='-O2 -arch i386 -arch x86_64' \
CXXFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \
./configure --disable-dependency-tracking
Now let’s build and install libmcrypt itself.
make
sudo make install
You can run make -j8 if you’re on a Quad-Core i7 and are curious how much it speeds up compilation, it makes no difference for installing mcrypt.

With libmcrypt ready to use, we need to compile the php extension for it.

cd ~/Source/lion/php-5.3.6/ext/mcrypt
/usr/bin/phpize
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \
LDFLAGS='-O2 -arch i386 -arch x86_64' \
CXXFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \
./configure --with-php-config=/Developer/SDKs/MacOSX10.7.sdk/usr/bin/php-config
make
sudo make install
Everything should be ready to hook up at this point, we’ll need to update /etc/php.ini to tell php to load the extension.

Verify that /etc/php.ini exists. If you’ve never worked with it before, or have just upgraded to Lion, you’ll need to copy php.ini.default to php.ini with:

# skip this step if /etc/php.ini already exists.
sudo cp /etc/php.ini.default /etc/php.ini

Update php.ini and tell php to load our newly compiled mcrypt.so

sudo nano /etc/php.ini

Add the following to the end of the file, then save and exit:

extension=mcrypt.so

Now restart Apache:

  • Open System Preferences
  • Select Sharing
  • Uncheck and re-check “Web Sharing”—this restarts the web server.
    • For some reason my Web Sharing was unchecked even though Apache was already running, if this happens to you, just “check/uncheck/check” to make sure it’s actually restarted.
Verify in your phpinfo() that mcrypt is really there, it should look like this:
Screen grab of what mcrypt should look like on the phpinfo page.
~Enjoy!
Tweet
lion, mcrypt, os x, php

7 comments on “Adding mcrypt as an extension to PHP on OS X 10.7 (Lion)”

  1. Richard Warner says:
    August 1, 2011 at 1:53 pm

    Doesn’t work. where exactly should I be with this command? in the mcrypt directory or the phpsize directory

    cd ~/Source/lion/php-5.3.6/ext/mcrypt
    /usr/bin/phpize

    • craig says:
      August 2, 2011 at 1:46 pm

      You’ll want to be in the ext/mcrypt directory when you run phpize. If you still get an error post it here, I’ll see what I can make of it.

  2. erwin says:
    August 2, 2011 at 11:53 am

    Thanks .. you save my time … trying to run after the lion
    ( I upgraded my MacBook .. some pieces still under 32bits w SL .. so need to recompile them to 64)bits w last dev kit …

  3. Ed says:
    August 5, 2011 at 11:26 pm

    Thanks for the great instructions!

  4. John Galt says:
    September 5, 2011 at 5:34 am

    I found several websites that tried to explain how to do this and yours was the only one that had instructions that a newbie like me could follow. Thank you for taking the time to document and share this information. You saved me a lot of headaches.

  5. John Galt says:
    September 5, 2011 at 6:09 am

    I got this working just fine on our Lion server but I am having some trouble on SL server 10.6.8. Can you please tell me what modifications I need to make? I tried to modify the command in step 2 but changing the deployment target to 10.6 but it returned an error.

    checking for C++ compiler default output file name… configure: error: C++ compiler cannot create executables
    See `config.log’ for more details.

  6. John Galt says:
    September 5, 2011 at 7:17 am

    Ugh, nevermind, I forgot to install Xcode.

Random Portfolio Pieces

About Craig

I'm a seasoned developer who codes, consults, trains and more. Download my resume, or visit my portfolio to learn more.

  Craig's Resume

Twitter Feed


Follow @ckh2oman on Twitter

Categories

  • Cycling
  • Family
  • JRuby
  • Link
  • MongoDB
  • Movies
  • MySQL
  • Node
  • PHP
  • Portfolio
  • Programming
  • Random
  • Road to Fitness
  • Ruby on Rails
  • Shell/Unix
  • Weight Lifting
  • WordPress

Archives

  • February 2012 (4)
  • January 2012 (14)
  • December 2011 (4)
  • November 2011 (3)
  • October 2011 (1)
  • August 2011 (2)
  • July 2011 (13)

Obligatory Tag Cloud

.net ajax asp.net cakephp code editing coffee script coldfusion cycling dailymile dblizzy execjs family fitness flash health html/css ide java jquery jruby kids lion magnolia mcrypt mongo monkey brain mysql os x oxrocket pdf php ruby ruby debugging rubygems rvm shell scripting silverstripe social twitter undefined method website weight weight lifting wordpress xml

(c) 2012 Craig Waterman | Technologist, Software Engineer | Syracuse, NY - Web Design by Jason Bobich