Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dean's avatar
Level 7

For those who find Homestead/Vagrant/Virtualbox slow on Windows

There are a few threads on here and laravel.io in regard to how slow homestead can be on Windows. I appear to have solved this, or at least improved it drastically, without the negatives associated with some of the methods I've see mentioned.

Basically, you just need to change the VM to use a fixed sized 'drive' rather than a dynamically sized one. I'm not going to try write a guide on how to make this change on an existing vm 'drive' because it was a bit messy the way I did it, but there are a few guides you can find via google.

There are a couple of other tweaks I've done that improved speed slightly, but by far the most major performance increase came from the above.

Not sure if this has improve the random freezes I get when using vagrant ssh through git bash, but it's improved page loading substantially.

0 likes
42 replies
opilo's avatar

Can you please describe how you changed the drive to fixed size?

opilo's avatar

Is there a way i can configure homestead to create a fixed size drive, instead of modifying the existing drive?

bashy's avatar

There's a few ways, some stuff here https://gist.github.com/christopher-hopper/9755310

And could be possible to edit the Vagrantfile for Homestead (taken from some random Vagrantfile on GitHub)

vb.customize ['createhd', '--filename', diskname, '--size', 8 * 1024]
vb.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', diskname]

Personally, I don't think it will give that much performance gain. Reading up on it (creators of VirtualBox) saying it's not that much different apart from if you make the disk really small and the data (sectors) are close together.

phazei's avatar

I'd like to suggest another method to speed it up. (That does work in windows now!)

From this archived forum: https://laracasts.com/forum/?p=1757-slow-responses-on-homestead/0

Enabling NFS makes it significantly faster.

@Stricken suggested the following:

    # 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
    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

And @adamwathan mentioned:

Make sure you edit /etc/nginx/nginx.conf and set "sendfile" to off if using NFS or you will run into weird caching issues.

I wanted to add to that discussion, but the thread is archived. It comes up as one of the first results for a search of the issue, so it's a shame I can't link from there.

It was mentioned in that thread that that solution doesn't work on Windows. Fortunately, I must missed that part and went to find a solution for NFS in windows. So I was lead to here, and found this great plugin that adds NFS support to vagrant in Windows. Simply install it:

$ vagrant plugin install vagrant-winnfsd

And add that NFS code to the homestead.rb (in windows C:\Users\username\AppData\Roaming\Composer\vendor\laravel\homestead\scripts\homestead.rb)

Find the section where it's already looping through the settings["folders"] and replace it with the nfs code.

And you should see massive speed increases.

EDIT: Added sort of folder in code to fix bug in winnfs

10 likes
bashy's avatar

Should be on by default for Homestead ^

2 likes
sivaprasad's avatar

It seems working for me. thank you so much for guidance. I see there is delay in pages response in browser. any help in improving pages response ?

saul.lopez's avatar

I've just implemented @phazei nfs steps and it works great. Great performance improvement! I'm using Windows 7 64bits

Shovels's avatar

I've tried @phazei instruction's above and unfortunately vagrant hangs when mounting NFS shared folders. Any ideas?

dusangregor's avatar

@Shovels try to disable firewall, i have same problem and after reconfiguring my windows firewall it works great and fast. Thanks @phazei.

Shovels's avatar

@dusangregor Thanks for the tip, I tried disabling the firewall but I still get the following:

==> default: Exporting NFS shared folders...
==> default: Preparing to edit nfs mounting file.
[NFS] Status: halted
[NFS] Start: started
==> default: Mounting NFS shared folders...

At this point it just freezes

phazei's avatar

If it's not mounting properly, this might fix it if multiple folders are being attempted: https://github.com/GM-Alex/vagrant-winnfsd/issues/12#issuecomment-78195957

Basically there's a problem where path length makes a difference and mounting breaks if a longer dir path is before a shorter one. So they need to be in length acceding order, weird, huh?

Also, it seems that sometimes mounting it the first time works, but not subsequent times. The winnfsd service doesn't stop itself when stopping vagrant, so it needs to be killed manually between instances.

Oh, and make sure to update the vagrant winnfsd, there have been a number of fixes recently.

Hopefully that will help some people.

1 like
juliofagundes's avatar

From:

"Booting (978.98ms)"

To:

"Booting (31.56ms)"

Wow! =D Thanks my friend.

EliasSoares's avatar

I've done this, and set sendfile off, but i'm havin problems with caching... Someone know how to solve this?

rjsworking's avatar

Hi

Had lots of problems after cloning github/bitbucket repos. Could not manually remove files, folders, etc. Back to dev on windows side and only use homestead for services that are not available in windows like beanstalkd, latest redis or any other.

Cheer

amiroo's avatar

Every time after "homestead suspend", when I wanna turn homestead on again with "homestead up", it seems that works but website cant load in browser. so I have to destroy homestead and build it again to woks. (in this case when it loads, it will also open another cmd panel for vagrant-winnfsd, but for first case it doesn't come up) any idea? thanks

Shovels's avatar

Thanks @alberto1el I actually run Windows, so needed to install the plugin (https://github.com/GM-Alex/vagrant-winnfsd ) but that didn't work either. (That is unless you mean this needs installing on the VM??)

In the end I ended up getting the VMWare license and VMWorkstation. NFS worked straight out the box :)

alberto1el's avatar

@Shovels, I did mean inside the VM, I also run Windows (7) and got the same error, after I installed the nfs server on the VM then I was able to 'vagrant up' and have the files synced, now is working smooth. (virtualBox for provider)

Shovels's avatar

@alberto1el ahh... Thanks for the clarification - I'm guessing this means you need to do this every time you re-provision the box, or have you been able to add this to part of the config?

sitesense's avatar

@Shovels

Homestead.yaml

folders:
    - map: ~/Code
      to: /home/vagrant/Code
      type: "nfs"

That's all you need, Homestead will take care of the rest.

Shovels's avatar

Thanks @sitesense - It was more if/where the following line was put into the config so that it's there the next time the box is created:

sudo apt-get install nfs-kernel-server
alberto1el's avatar

@sitesense I am not trying to disagree with you or anyone on this post but I did get the same 'error' @Shovels got:

==> default: Exporting NFS shared folders...
==> default: Preparing to edit nfs mounting file.
[NFS] Status: halted
[NFS] Start: started
==> default: Mounting NFS shared folders...

And the way I found out to make it work on my machine was to run this command on the VM

sudo apt-get install nfs-kernel-server

(Which I found here https://laracasts.com/discuss/channels/requests/nfs-on-homestead-20/replies/23098 )

Also edited the homestead.rb file (\Homestead\scripts\homestead.rb)

#Long short path bug
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|
    mount_opts = folder["type"] == "nfs" ? ['actimeo=1'] : []
    config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil, mount_options: mount_opts
  end
end

(I also the configured the yaml file with 'nfs' for the folders and installed the plugin (winnfsd) as instructed).

And @Shovels I have not tried to get that line in the provision script, at this point I do not know if it is a bug or a particular scenario we have, for now I only use that machine for a Laravel5 app I am working on.

3 likes
sitesense's avatar

@alberto1el Sorry, I hold my hands up! It seems I misunderstood the instructions on the Homestead installation page. Well, not misunderstood but took for granted that if the NFS flag was set then it would be installed when provisioned.

I have since looked at the script that provisions the VM and NFS is indeed NOT installed, so a bit of a let down - and a shortfall in the docs there.

A shame because it doesn't look that difficult to add.

Maybe this might help...

You'll find a file called after.sh in your .homestead folder. It's probably as simple as adding the command in here:

#!/bin/sh

# If you would like to do some extra provisioning you may
# add any commands you wish to this file and they will
# be run after the Homestead machine is provisioned.

4 likes
Next

Please or to participate in this conversation.