How I use Laravel Homestead everyday

I feel like I’ve been talking about homestead a lotlately. I feel like Vagrant is such an important part of a developer’s workflow. If you are still using MAMP, WAMP, or installing Virtual Machines manually you are wasting so much of your own time (and your clients money) by not using prebuilt development environments.

Homestead is what Taylor Otwell created to make it ridiculously easy for Laravel users to develop in similar environments that Forge uses for deployments making the developer experience from Homestead to Forge very seamless.

The first version of Homestead (1.x) was rough around the edges compared to the easy to use version 2.x. I really enjoyed the 1.x version since it was easy to drop in a vagrant configuration per project. As it turns out this wasn’t how Taylor and others used Homestead.

The 2.0 version introduced a global command to use that interacted with a global vagrant machine. This was quite easy to configure because the homestead executable did all of the vagrant commands for the user. You had one yaml configuration file to manage as many projects as you wanted to configure. This was a great solution to a lot of people. What about when it comes to easily sharing your development environment with contributors (or making it easier on potential new contributors)?

I prefer to have my open source projects contain a Vagrant environment so that any potential contributor can easily clone my repository and run “vagrant up”. Collaborators running the same development environment as I am is just as important since so many potential environment differences can be mitigated easily. Also I can further configure the environment by adding to the “after.sh” shell script. I often use this to add tools such as phantomJS and screen for doing acceptance testing with Codeception.

Now we should have a fully working vagrant machine. You can quickly check by going to http://localhost:8000 and you should see the default Laravel welcome screen. I always map a fake domain to my projects so if you add this line to your hosts file (/etc/hosts on *nix systems, C:\Windows\System32\Drivers\etc\hosts on Windows) you can use the http://homestead.app url to see your application.

192.168.10.10 homestead.app

What about non-Laravel applications?

Follow the same steps and then edit Homestead.yaml in the root of your project and adjust those settings as needed. if you need to do more customizations edit the after.sh script, it will be run the first time you run ‘vagrant up’ and if something isn’t working right, simply ‘vagrant destroy’ and ‘vagrant up’ again.

Sharing your Homestead environment

You should add these files to your version control: ‘Vagrantfile’, ‘after.sh’, ‘aliases’. You should not version control ‘Homestead.yaml’ (make sure you add it to .gitignore!) since the paths of the folder will not be the same on someone else’s system. Instead you should instruct potential collaborators to run the make command for themselves, no existing files will be overwritten:

$ php vendor/bin/homestead make
Homestead Installed!

What about existing Laravel applications?

Follow the same steps and you’ll be up and running with your own Homestead in minutes!