Run #AllTheCommands Outside of Homestead
Install latested 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).
However, 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!
- OS X Yosemite (already installed)
- Laravel Homestead 2.x (already installed with shared folders set up)
- PHP for OS/X
- Open Terminal.
- Let’s head to your home directory and install PHP 5.6 (the latest version as of now):
3. If you are using Oh-My-ZSH:
And prepend “/usr/local/php5/bin:” to the “export PATH” string, like so:
4. If you are using Bash (default):
And add the following line at the end (if you already have entries there):
5. Quit and restart Terminal.
6. Go to one of your Laravel projects in your Homestead-shared folder (don’t SSH into Homestead though), and run:
If all went well, you should be greeted by the following output (you will most likely have a newer version of Laravel installed):
And The Icing
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, changing