I’m doing some work on a project that is using PHP, and have been working on setting up some continuous integration build scripts to make sure that we have a shot at catching errors before they make their way to production.
Call to undefined function mcrypt_get_iv_size()
So some quick Google searches, and I found a couple of blogs with “how to” install the library (links at the end of this post), and proceeded to get this done.
First step was to download the mcrypt from SourceForge at http://sourceforge.net/project/showfiles.php?group_id=87941
Once I had the file, I opened a command prompt and ran:
tar xvfz libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8/
Next I ran configure, setting the appropriate flags for my envirionment (note – I didn’t do this for the other configures, probably would have been a good idea):
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 –disable-dependency-tracking
This sets up the make file, so you can run the next two commands:
sudo make install
Next to make the PHP library, I needed the PHP source files, so I went out and grabbed PHP 5.3.15 (since that’s the version I have when I run php -version) by going to http://us3.php.net/get/php-5.3.15.tar.bz2/from/a/mirror. Note that you can simply change the version number in that URL to get the version you need.
Once I had that I did the following:
tar xvfz php-5.3.15.tar.bz2 cd php-5.3.15/ext/mcrypt /usr/bin/phpize
This of course gave me an error about autoconf not being installed:
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
From there I installed autoconf by doing the following:
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
Then back to the php mcrypt folder and reran the phpize step to and finish building:
/usr/bin/phpize ./configure make sudo make install
Finally an edit to the php.ini file which was simply to add the extension:
And of course a quick restart of Apache and the extension shows up and I can run my unit tests successfully.