Install latest PHP5+MCrypt on Yosemite to enable Laravel Artisan
Laravel Homestead has brought virtual machines for web development to the mainstream PHP developer: it makes setting up a development stack similar to XAMP extremely simple. You no longer need to be a pseudo sys-admin to set up Vagrant and Puppet to manage your environments.
However, one of the drawbacks so far has been that you always needed to run Laravel Artisan commands from within homestead, as they depending on MCrypt being installed (which OS X has not yet included by default). The main drawbacks are slow execution (running commands inside homestead is not near as fast as running them natively — I suspect this mostly has to do with the Vagrant Shared Folders feature) and the annoyance of always having to SSH into homestead.
The accepted solution thus far has been to install newer versions of PHP alongside Apple’s version using Homebrew or MacPorts. This would likely require you to compile the MCrypt extension manually. I also found that Homebrew could leave your system in disarray if things went wrong (more than once I had to do a complete restore because of this).
There’s another method I came across while research some non-related issues: install the latest version of PHP from a binary that includes the MCrypt extension. It will not bork up your system if you want to remove it, either. 😀 Let’s get cooking!
If all went well, you should be greeted by the following output (you will most likely have a newer version of Laravel installed):
We still have the one command that won’t play nice, though:
php artisan migrate. There’s a fix for that too:
In your project, edit config/database.php, change the
mysql section (specifically the
DB_HOST directive) to something like this:
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST') . (('homestead' === env('DB_USERNAME', 'forge') && 'homestead' !== gethostname()) ? ':33060' : ''), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''),