How to Install mcrypt for php on Mac OSX Lion 10.7 Development Server
The mcrypt extension is missing. Please check your PHP configuration.
The above error appears after you successfully get phpMyAdmin up and running on OS X, generally you don’t have to worry about it, you only need to address the error if you are going to use a web application that requires it, for example Magento, the shopping cart software.
mcrypt is a file encryption method using secure techniques to exchange data.
Xcode
Get Xcode from the Apple app store, free download version, then install it from the /Applications folder it will be called ‘Install Xcode’ or just Xcode.app. You need this to use the compilers to compile the source code that you will download.
Getting it on in OS X Lion
This tutorial works mostly in the Terminal, launch it from /Applications/Utilities, cd to home account and make a directory that you will work in, call it mcrypt
cd ~ ; mkdir mcrypt ; cd mcrypt
Get libmcrypt 2.5.8 from Sourceforge
Get the php code in a tar.gz format- (version 5.3.1 and 5.3.6 work ok, I had issues with 5.3.9 and 5.3.10)
Find out your current version of php and download the appropriate version:
php -v
Move both of these files that you downloaded into your working directory – mrcypt in this instance and go back to Terminal
cd ~/mcrypt
Expand both files:
tar -zxvf libmcrypt-2.5.8.tar.gz
tar -zxvf php-5.3.6.tar.gz
Remove the compressed archives
rm *.gz
Configuring libmcrypt
cd libmcrypt-2.5.8
./configure
make
sudo make install
With the libmcrypt configured now ready, time for to make the mcrypt extension.
Compile mcrypt php Extension
cd ../php-5.3.6/ext/mcrypt/
/usr/bin/phpize
Output should be:
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
./configure
make
sudo make install
The result of this should be:
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20090626/
Enabling mcrypt.so php Extension
Open etc/php.ini and add the line below at the end
extension=mcrypt.so
If there is no php.ini file, then you need to make one from php.ini.default in the same location like so:
sudo cp /etc/php.ini.default /etc/php.ini
And allow write capability
chmod u+w php.ini
Then add the line as above.
Restart Apache
sudo apachectl restart
That’s it, check your phpMyadmin login page or create and browse to a phpinfo.php to see if it loaded correctly, if it didn’t load you may need to declare the extensions directory in /etc/php.ini
extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626/"
Hopefully it wasn’t too much of a nightmare…
Related posts:
- How to Migrate Drupal Site to a local Development Server & Fix Clean URLs
- Fastest Way to install WordPress on OSX Lion 10.7 and 10.6
- Installing phpMyAdmin on Mac OSX 10.7 Lion & 10.6 Snow Leopard
- Forbidden 403, You don’t have permission to access /~username/ on this server
- Install and configure Apache, MySQL & PHP on OS X Lion 10.7 and 10.6


January 14, 2012 


