Setting up Laravel Homestead on Windows with Vagrant and VirtualBox
Homestead is here to make our lives simpler by offering a prepackaged virtual machine with all dependencies required by Laravel. If you are reading this, you probably tried to follow the official guide, but all you got is a timeout when accessing http://homestead.app. This article will help you set up the default configuration. Tested with Git 2.11.0, Vagrant 1.9.1, VBox 5.1.12, Homestead base image 1.0.1, Homestead 4.0.0, and Windows 7 x64.
Note: If you opt-out from adding optional Unix tools to your environment during Git installation, you will have to use Git Bash instead of Windows cmd (command prompt). After installation, log out or restart your PC so the changes to you PATH become effective.
In a nutshell
- Add 192.168.10.10 homestead.app to end of C:\Windows\System32\drivers\etc\hosts file
- Create directory structure: C:\Users\[YourUsername]\Code\Laravel\public and create index.php file with any content
- Open command prompt of your choice
- Generate ssh public key (use defaults by pressing enter): ssh-keygen -t rsa -C "firstname.lastname@example.org"
- Download Homestead base image (~1GB): vagrant box add laravel/homestead
- Navigate to C:\Users\[YourUsername]: cd %USERPROFILE%
- Clone Homstead settings: git clone https://github.com/laravel/homestead.git Homestead
- Navigate to Homestead directory cd Homestead
- Start Homestead VM: vagrant up
- Open your browser and go to http://homestead.app
Pro tip: To open Windows cmd (command prompt) in any directory, hold SHIFT and right-click on empty space anywhere in directory. Select Open command window here from the extended menu.
Useful vagrant commands
vagrant up # Start VM (will Download/Create image) vagrant halt # Stop VM vagrant provision # Update VM settings based on Homestead.yaml while VM is running vagrant destroy # Delete VM
Running in wrong directory
>> vagrant up A Vagrant environment or target machine is required to run this command. Run `vagrant init` to create a new Vagrant environment. Or, get an ID of a target machine from `vagrant global-status` to run this command on. A final option is to change to a directory with a Vagrantfile and to try again.
Solution: Make sure you are in your Homestead directory. Navigate to C:\Users\[YourUsername] with cd %USERPROFILE%, and clone the Homstead settings with git clone https://github.com/laravel/homestead.git Homestead. Navigate to Homestead directory using cd Homestead and run vagrant up.
>> vagrant up C:/Users/[YourUsername]/Homestead/scripts/homestead.rb:4:in 'configure': undefined method '' for nil:NilClass (NoMethodError) from C:/Users/Gex/Homestead/Vagrantfile:33:in 'block in <top (required)>'
Solution: Navigate to C:\Users\[YourUsername]\Homestead and run init.bat or init.sh to initialize Homestead and automatically create C:\Users\[YourUsername]\.homestead.
Missing SSH public key
>> vagrant up C:/Users/[YourUsername]/Homestead/scripts/homestead.rb:117:in `read': No such file or directory @ rb_sysopen - C:/Users/[YourUsername]/.ssh/id_rsa (Errno::ENOENT)
Solution: Run ssh-keygen -t rsa -C "email@example.com" anywhere to generate you public key in C:\Users\[YourUsername]\.ssh\id_rsa.pub
Missing Code directory
>> vagrant up * The host path of the shared folder is missing: ~/Code
Solution: Create directory structure: C:\Users\[YourUsername]\Code\Laravel\public and create index.php file with any content.
Missing hosts entry
This site on the company, organization or school intranet has the same URL as an external website. ERR_ICANN_NAME_COLLISION
Solution: Add 192.168.10.10 homestead.app to end of C:\Windows\System32\drivers\etc\hosts. To make sure you changes are immediately effective, run ipconfig /flushdns command.
Vagrant Homestead VM not started
homestead.app took too long to respond. ERR_CONNECTION_TIMED_OUT
Solution: Navigate to C:\Users\[YourUsername]\Homestead and run vagrant up
Missing directory structure
No input file specified.
Solution: Create directory structure: C:\Users\[YourUsername]\Code\Laravel\public
403 Forbidden nginx/1.11.5
Solution: Create index.php with any contents in C:\Users\[YourUsername]\Code\Laravel\public