You are here

Windows+Vagrant+WinNFSD Without File Update Problems


I have used Windows to develop on for years. I have been through WAMP, XAMPP and EasyPHP, plus also going my own route to handle my web development. Last year I switched to Vagrant so that I could mimic the varying servers I work with from all my clients. Of course I was quickly plagued with the problem most Windows vagrant users face - extremely slow page loads.

The problem comes from shares. Using VirtualBox native sharing is horribly slow. You can use Windows sharing (SMB), but that is also painfully slow. A Drupal 8 bare install was taking 5 seconds to load the home page. That alone can add to the gray hair count rather quickly.

I also use PHPStorm, so decided to try using their remote server capabilities and even RSync sharing. Of course when working with Drupal these have a big problem. If you install a module via drush, or generate code via Drupal console, you need to remember to refresh the files on your local machine or you won't have them. I'm getting older now and remembering things like that becomes harder.

So what was the solution now? Well, NFS would be nice, but that is Linux based systems only, but luckly there is the vagrant-winnfsd plugin, which adds NFS support to Windows, giving you the same, lightening fast file access times that Mac and Linux users enjoy. This was such a joy....well for a few hours at least. It seems that after a period of time that the files stop refreshing on the server.

The files not refreshing quickly messed with my MoJo. Suddenly I'm hitting refresh and wondering "what is going on?". I would SSH into the machine and notice the file hadn't updated.

Then another problem crept up. I've got some clients running multiple items on different servers, meaning I needed multiple machines. Well the WinNFSD plugin for Vagrant doesn't really like that. I would try to start a second machine, or even stop the first one and start another. Then I would get hangs at the mounting process, or the boot complete and the folders not mount at all.

Back to hours of Google, troubleshooting and hair pulling. I found countless complaints of the same thing, but never any real solutions. Could it really be this hard?

Finally! I decided to look at the actual repository for WinNFSD . Low and behold I found a batch file there for running the daemon as a service. Now this started clicking in my head. Share everything I need through a service and then simple restart it when the files weren't refreshing. Setting it up was also extremely simple. For this example, we'll do it in a directory called C:\winnfsd.

  1. Uninstall the vagrant-winnfsd plugin.
  2. Create a folder on your system for your new WinNFSD service files.
  3. Grab winnfsd.exe and put it in that folder (download from here)
  4. Grab the nfsservice.bat file and put it in that folder (get it here)
  5. Create a text file in that folder. For this example, we'll name it exports.txt.
  6. Copy the share folders from your vagrant files and place in that text file, one share per line.

Now all you have to do is open a command prompt in that directory (do it with administrative permissions) and simply execute:

nfsstart.bat start C:\winnfsd\exports.txt (or whatever you name the export files)

A couple important notes here

  • The path to your exports file must be absolute.
  • You must do this with administrative permissions, thanks to Windows screwy permissions system.

Now you got WinNFSD running as a service. You can even stop it by changing "start" to "halt" in the command above.

And if you have been using the vagrant-winnfsd plugin, there's no need to change anything in your vagrant files. You already have them setup to use these shares with NFS. The only thing is that Vagrant won't start winnfsd.exe, since you're running it as a service now!

And for the real bonus. I've had a machine up and running over 72 hours now, working on a project the last few days. In that time the files have not failed to update once, and it remains lightning fast.

**Double bonus. I'm lazy and get tired of going from command window to command window. So to counter that, I created a couple simple shortcuts on my desktop. One to start the service and one to stop them. And if you're on Windows 10, you can right click these shortcuts, select the compatibility tab and check to run as administrator. No more having to remember that step either!