After many hours of teeth gnashing, I’ve managed to get the latest version of PHP (5.4.11 at this time of writing) working with the built-in Apache version on Mac OS X 10.8.2 (Mountain Lion) and libmcrypt.
Since I’ve decided to give the Laravel framework a try, I had to have libmcrypt and the PHP MCrypt extension since that is a requirement of the framework.
Here is a quick rundown to help you out.
Prerequisites:
Make sure you update to the latest Command Line Tools for Xcode!
You can download it at https://developer.apple.com/downloads/
Requirements:
Step 1: Downloading packages
Go ahead and download the latest version of PHP from the site
http://php.net/downloads.php#v5
Also download the latest version (2.5.8) of libmcrypt, not mcrypt.
http://sourceforge.net/projects/mcrypt/files/Libmcrypt/
Step 2: Compiling
Unpack both PHP and libmcrypt with your favorite unpacker, or use the terminal command.
tar xvzf php-5.4.11.tar
tar xvzf libmcrypt-2.5.8.tar
Start configuring and compiling libmcrypt, but not PHP.
./configure
make
make install
Install PHP 5.4.x via Homebrew. Since it’s not in the default tap, you’ll have to use some terminal commands to get to the apache-php tap.
Punch in
brew tap homebrew/dupes
to get to the tap which holds some of the dependencies. Then run the following:
brew tap josegonzalez/homebrew-php
Now we can install PHP 5.4.11 via homebrew. To do so, run
brew install php54
Let it do it’s thing, it might take a while.
Step 3: Configuring Apache
Open up your apache configuration file in
/private/etc/apache2/httpd.conf
and change the line of your php5_module to
LoadModule php5_module /usr/local/Cellar/php54/5.4.11/libexec/apache2/libphp5.so
Good now Apache will use the PHP version we installed via homebrew.
Now edit your Bash or ZShell PATH, and add this line
export PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"
Restart your terminal and verify that your shell is using the PHP binary you installed through homebrew via
which php
It should point you to
/usr/local/opt/php54/bin/php
Step 4: PHP MCrypt extension
Go to the PHP version you downloaded via their website and navigate to the
/ext/mcrypt
folder. Punch in the following commands:
/usr/bin/phpize
./configure
make
make install
And you’re done installing the MCrypt extension. Now to tell PHP to use that extension.
Go to the php.ini file located at
/usr/local/etc/php/5.4/php.ini
and add the following line to the file, under “Dynamic Extensions”
extension=libmcrypt.so
And you’re all done! Confirm that mcrypt is installed by running
php -i | grep mcrypt
and it should say
mcrypt support => enabled

And now you’re all done, when visiting your Laravel site you’ll be greeted by their welcome page!
