Laravel Homestead/Vagrant/Virtualbox is slow on Windows
On laracasts forum the author named @phazei
has answered it 3 years ago
What he said was:
1) on your Windows host install plugin that adds NFS support to vagrant in Windows.
$ vagrant plugin install vagrant-winnfsd
2) find your homestead.rb
I found it in
C:\Users\username\Homestead\scripts
even though he suggested to look at
C:\Users\username\AppData\Roaming\Composer\vendor\laravel\homestead\scripts
3)
Find the section where it's already looping through the settings["folders"] and replace it with the nfs code.
for me it was somewhere about line 140.
So, I commented out all statement if settings.include? 'folders' ... end
and added this instead:
# EDIT:
# Reorder folders for winnfsd plugin compatilibty
# see https://github.com/GM-Alex/vagrant-winnfsd/issues/12#issuecomment-78195957
settings["folders"].sort! { |a,b| a["map"].length <=> b["map"].length }
# Register All Of The Configured Shared Folders
if settings.include? 'folders'
settings["folders"].each do |folder|
config.vm.synced_folder folder["map"], folder["to"],
id: folder["map"],
:nfs => true,
:mount_options => ['nolock,vers=3,udp,noatime']
end
end
4) Then restarted vagrant with halt/up and my page load speed increased from 8 to 2 seconds.
Thank you @phazei
. Your answer is still working after 3 years.
PS
I tested it on windows 10 with Oracle Virtualbox-5.2.12, vagrant version-2.1.1.
PPS
You can run vagrant up --provision
, it will not affect the change you have made in homestead.rb
NFS stands for Network File System
and you need it for speed.
Laravel homestead tutorial
does not say what NFS
is and why you need it, which is why I ignored it on the initial install.
1) On your Windows host, install the plugin that adds NFS support to vagrant in Windows.
$ vagrant plugin install vagrant-winnfsd
2) Go to Homestead.yaml
, it usually sits in C:\Users\username\Homestead\Homestead.yaml
3) Add type: "nfs"
in the folders section like so:
folders:
- map: ~/code
to: /home/vagrant/code
type: "nfs"
4) Run vagrant up --provision
Result:
The speed increases, as in @phazei's
answer, from 8 to 2 seconds for each request, but it is much less work. @phazei's
answer clarifies some background processes.
I tested it on windows 10 with Oracle Virtualbox-5.2.12, vagrant version-2.1.1.
Please note: Vagrant NFS page says
Windows users: NFS folders do not work on Windows hosts. Vagrant will ignore your request for NFS synced folders on Windows.
But if you have the plugin, you can ignore it.