Install Homestead into your project
Joe • June 20, 2015
homestead laravel php vagrantI'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.
As Seen On
Recent Posts
- PHP to Rust via Copilot
- Compiling Python 3.12 from Source Tarball on Linux
- HTML Form Processing with PHP - php[architect] Magazine August 2014
- The Workshop: Local Dev with Lando - php[architect] Magazine November 2022
- Getting back into the swing of things
- All Posts
Categories
- ansible
- apache
- applesilicon
- aws
- blackwidow
- cakephp
- community
- composer
- conferences
- copilot
- data-storage
- day-job
- devops
- docker
- fpv
- general
- github
- givecamp
- homestead
- jigsaw
- joindin
- keyboard
- laravel
- learning
- linux
- maker
- mamp
- mentoring
- music
- nonprofit
- opensource
- packages
- php
- phparch
- projects
- provisioning
- python
- razer
- rust
- s3
- security
- slimphp
- speaking
- static-sites
- storage
- testing
- tiny-whoop
- today-i-learned
- training
- ubuntu
- vagrant
- version-control
- windows
- writing
- wsl
- wsl2
- zend-zray