[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.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.
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.3.6.tar.gz/from/nl1.php.net/mirror | tar -zx
cd /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
cd /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
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
Love the blog
Thank you
Thanx for your solution. You’re GREAT!!!!!!
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!
THANK YOU!!! this also solved my problem for the version 5.3.26 =]
Where is the facebook like button ?
It’s in the blue box just below the title :)
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!
Thank you very much for this addition!
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
andZEND_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.Thank you so much for this.. was stuck for hours
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!
Thank you :) Glad to be of service.
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.
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.
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.
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.
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
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)
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!
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 :)
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!
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
I’m sorry, I don’t have experience with 5.4.8 yet and will not look into 5.4.x until we’re preparing to move to 5.4.x ourselves
Thanks so much, sorry didn’t notice that you relied so soon :)
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
I am trying to follow this, but when I use “make -j6” I get “sudo make command not found”.
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 :)
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!
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 :)
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
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?
Thanks! This is the only tutorial that actually worked for me!
Quite welcome
You sir.. are awesome, this worked flawlessly!
Thanks!!!
Worked for me \o/
+1 for PHP_FE_END with {NULL,NULL,NULL}. Big thanks…
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
yeah.
make clean
is in effect the ‘I want to start over’ command :)Thanks for sharing.
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.
Thank you for this addition. Of course – since everything here is based on HomeBrew – you could also just do
brew install autoconf
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
Indeed. Take it one step at a time, don’t rush this. If you do it with care, you only have to do it once. (until the next OSX Upgrade ^^)
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
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.
“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!!
Quite welcome
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
looks like you’re missing the base developer tools. Take a look here and follow step 2.
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.
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!
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!
Thank you! This tutorial saved me hours!
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
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)