How to install PHP Mcrypt to Snow Leopard
The following instructions on how to install php mcrypt to Snow Leopard assume that you have a working Apache 2.2 / PHP 5.3 in place and want to add the php mcrypt module. It will work as a fresh install, but keep in mind that additional configuration steps after these instructions are necessary to get your web server working properly. Those additional steps are omitted here, as there are countless resources available on the Internet.
1. If you don’t already have the mcrypt module (in /usr/lib), download the libmcrypt source code from Sourceforge here. Then extract the downloaded file in a Terminal and move inside the created directory. (cd libmcrypt-2.5.8 in my case)
2. Execute the following lines in one command in your Terminal, if you have a 64bit version of Apache/PHP:
CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64" ./configure --disable-posix-threads
(for 32 bit versions: ./configure –disable-posix-threads)
2. In your Terminal, run:
3. If no errors, in your Terminal run:
$ sudo make install
4. Download the PHP source code from PHP’s website here. Extract in a Terminal and move into the extracted directory.
5. In your Terminal, run the following lines in one command:
export MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64"
./configure --prefix=/usr/local/php5 --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc --with-config-file-path=/etc --with-zlib --with-zlib-dir=/usr --with-openssl --with-iconv=/usr --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --with-mcrypt --enable-sockets --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-apxs2=/usr/sbin/apxs
6. Correct a bug in Makefile.
As a result of a bug in PHP 5.2.9 and 5.3.0, we’ll need to correct the file Makefile generated by the configure phase. Let’s add ‘-lresolv‘ at the end of the line that begins with ‘EXTRA_LIBS‘. Leave a space and add it like ” … -lz -licucore -lm -lresolv to whatever is there already. Do not alter the exiting text, simply add it.
7. In your Terminal, run:
8. If no errors, run:
sudo make install
At this point, restart apache and check your configuration with phpinfo(). Look for mcrypt as it should appear as an enabled module.