Vagrant and Homestead are here to make our lives easier 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.
Prerequisites
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\[Username]\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 "your@email.com"
- Download Homestead base image (~1GB):
vagrant box add laravel/homestead
- Navigate to C:\Users\[Username]:
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
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
# C:\Users\[Username]\Homestead
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
Common issues
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\[Username] 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 runvagrant up
.
Initialize Homestead
# C:\Users\[Username]\Homestead
>> vagrant up
C:/Users/[Username]/Homestead/scripts/homestead.rb:4:in 'configure':
undefined method '[]' for nil:NilClass (NoMethodError) from
C:/Users/[Username]/Homestead/Vagrantfile:33:in 'block in <top (required)>'
Solution: Navigate to C:\Users\[Username]\Homestead and run
init.bat
orinit.sh
to initialize Homestead and automatically create C:\Users\[Username]\.homestead.
Missing SSH public key
# C:\Users\[Username]\Homestead
>> vagrant up
C:/Users/[Username]/Homestead/scripts/homestead.rb:117:in `read':
No such file or directory @ rb_sysopen - C:/Users/[Username]/.ssh/id_rsa (Errno::ENOENT)
Solution: Run
ssh-keygen -t rsa -C "your@email.com"
anywhere to generate you public key in C:\Users\[Username]\.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\[Username]\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\[Username]\Homestead and run
vagrant up
Missing directory structure
No input file specified.
Solution: Create directory structure: C:\Users\[Username]\Code\Laravel\public
Missing index.php
403 Forbidden
nginx/1.11.5
Solution: Create index.php with any contents in C:\Users\[Username]\Code\Laravel\public