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 OSX Lion 10.9 installation and I have Xcode 5.01 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.4.17 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.4.17.tar.gz/from/nl1.php.net/mirror  | tar -zx
Installation
Make sure /usr/include/php symlinks to the correct php includes, available in the SDK within the Xcode.app bundle;
Shell commandsudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/php /usr/include/php

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

Shell commandcd /tmp/source/php-*/ext/mcrypt/
phpize
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 -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

Exit mobile version