Install Homestead into your project

Joe • June 20, 2015

homestead laravel php vagrant

I've previously shared a project I built that allowed you to easily add the Laravel Homestead vagrant environment into your project. My goal with the package was to give an easy way of installing the core homestead files into your project needed to have an isolated vagrant machine.

I pinged Taylor Otwell about possibly adding this sort of functionality to the homestead application itself. This spurred a really great back and forth of what this might look like.

I built out a new command for the homestead executable that would copy over the files from ~/.composer/vendor/laravel/homestead. This worked but the issue was it still required the user to have the homestead package installed globally.

I showed Taylor my progress thus far and we talked and decided it would be smarter to just require the laravel/homestead package into the current Laravel project. We had this idea during the mega twitter conversation. There wasn't much needed to make this change. We pulled the homestead files out of the vendor/laravel/homestead folder so we can easily keep the configuration up to date later as changes are made to Homestead.

Ultimately we got everything working and the result can be found in the Laravel documentation. Taylor helped smooth some of the rough edges of my code and we went through a few different names of the command before we landed on ‘make'.

From your project's root folder:

composer require laravel/homestead
php vendor/bin/homestead make

The required files will be copied to your project root and the Homestead.yml file will automatically be configured for you.

You can also set hostname and name values for the virtual machine. It is important to note that you can't have more than one vagrant machine with the same name. By default the make command will use your project's folder name as the box name.

php vendor/bin/homestead make -- name=VagrantName -- hostname=myhost

From here you can use the standard vagrant commands (vagrant up|halt|reload|). Make sure to add these new files to your version control and any contributors to your project will be able to easily use the same vagrant environment.

This is not just for Laravel projects! You can easily run this command for your application and edit the Homestead.yml file to fit your application.