Jens Segers on Oct 19 2015

Installing PHP 5.6 and Mcrypt on Mac OSX

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"

Because Homebrew is going to build a couple of things, you are going to need the Xcode command line tools as well:

xcode-select --install

Now simply install php56 and 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/

Now restart your apache using sudo apachectl restart and you're good to go!


albertovasquez 3 months ago

@fusco brew install homebrew/php/php56 homebrew/php/php56-mcrypt

fusco 5 months ago

I have an error with 'brew install php56 php56-mrcrypt'

Adam 8 months ago

Oh my gosh, thank you. Didn't know about this config option.

saravm2h 11 months ago

After hours of searching, your blog helped me fix it! Thank you so much!

igordla 1 year ago

After searching in many websites. Your post saved my bacon. So, thanks!