[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.11I 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;
php --version
Now you will see the version number of your PHP; you will need to match the source version with this. Mine is 5.5.14 for PHP and I downloaded the 2.5.8 version of mcrypt. If you use different versions, then substitute the correct version numbers.
mkdir /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.5.14.tar.gz/from/nl1.php.net/mirror | tar -zx
cd /tmp/source/libmcrypt-2.5.8
MACOSX_DEPLOYMENT_TARGET=10.10 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
cd /tmp/source/php-*/ext/mcrypt/
phpize
MACOSX_DEPLOYMENT_TARGET=10.10 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
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
error: 'PHP_FE_END' undeclared here (not in a function)
Same thing might happen with function ZEND_MOD_END .
After fixing, issue the commands
make -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
cd ~ && rm -rf /tmp/source
Activation
Edit your PHP configuration
sudo nano /etc/php.ini
if “New file” is shown, please copy php.ini.default to php.ini first.
[ ! -f "/etc/php.ini" ] && sudo cp /etc/php.ini.default /etc/php.ini
other tutorials tell you to set
enable_dl=on
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
- click Apple > System Preferences > Sharing
- disable Web Sharing
- 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
php --info | grep crypt
you should see:
mcrypt support => enabled
Now you’re done!
Footnotes:
August 2014: Updated for OSX 10.10 Yosemite
July 2013: Updated for OSX 10.9 Mavericks