Space Cat, Prince Among Thieves

Install PHP Mcrypt Extension in OS X

This is verified to work in macOS Sierra but should work at least in Mavericks if not older as well. Let me know if issues should arise.

These directions are for working with the native installation of PHP. Your results may vary if you are using a brew or otherwise installed version of PHP.

We need install the required dependencies. If you are not already using Homebrew you will need it.

$ brew install autoconf pkg-config libmcrypt

Next we will download the PHP source. Verify the exact version of PHP you are running.

$ php --version

This should output something along the lines of the following. The version is highlighted.

PHP 5.6.27 (cli) (built: Sep  9 2014 19:09:25) 
Copyright (c) 1997-2014 The PHP Group

Now we move into a working directory and download the source making sure to update the following for the version from above.

$ cd /tmp
$ mkdir mcrypt
$ curl -L http://php.net/get/php-{{version}}.tar.bz2/from/this/mirror > php.tar.bz2
$ open php.tar.bz2

Now we will compile and test the Mcrypt extension.

$ cd php-{{version}}/ext/mcrypt
$ phpize
$ ./configure
$ make
$ make test
$ sudo make install

If all that goes well finally we'll need to add the following to our php.ini - I usually add at it at the end of the file.

extension = mcrypt.so

You can verify your installation with the following:

$ php --info | grep mcrypt\\.

Lastly, depending on your setup now you may want to restart apache.

$ sudo apachectl restart

Comment by: Kevin on

Kevin GravatarWhere is php.ini?

Comment by: Jonathan on

Jonathan GravatarThank you for this. I must've tried half a dozen different guides doing all sorts of strange things in my attempts to install mcrypt. This guide was the most clear, concise, and easy to follow. I am not certain what PEAR is being used for though.

Comment by: Jesse G. Donat on

Jesse G. Donat GravatarGood catch! The PEAR piece was left over from an older version of the guide that utilized PEAR's `pecl` command. I have updated the guide accordingly.

Comment by: Anant on

Anant GravatarThank you , steps are pretty simple and its working

Comment by: kmabas on

kmabas GravatarDon't forget disable SIP in El capitan and earlier and if "phpize" doesn't work, is because you need to install xcode cli tools

Email address will never be publicly visible.