Years ago I wrote a blog post on how to install the PHP mcrypt extension on OSX. But times change, and here's how you do it, for real.
Disclaimer: I personally use Vagrant instead of setting up PHP and Nginx on my local machine. This allows me to quickly switch between completely different development environments. But if you prefer to have PHP and Apache running locally, then this post is what you are looking for.
First things first, you need Homebrew, seriously. It is a package manager that simplifies the installation of software on OSX. Install it by either going to their website and follow the installation instructions or just execute this in your terminal:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Because Homebrew is going to build a couple of things, you are going to need the Xcode command line tools as well:
Now simply install
php56-mcrypt using Brew with this simple command:
brew install php56 php56-mcrypt
All that is left now is to tell Apache to use this new PHP version by editing your
/etc/apache2/httpd.conf file. Search for the line that starts with
LoadModule php5_module and change it to this:
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
Now restart your apache using
sudo apachectl restart and you're good to go!