How to enable NFS on Laravel HomesteadLast updated: 2016-01-26 :: Published: 2016-01-19 :: [ history ]
I currently work on a Laravel project composed of multiple microservices that I run locally using Homestead (box v0.4.0 at the time of writing). As I started tinkering around I noticed that requesting the different APIs was super slow - up to 20s per request, which was really unexpected (and annoying to say the least).
Googling around it appeared that most fingers were pointing to the same suspect: VirtualBox’s shared folders system. Most people were also advising to use NFS instead, and as a matter of fact there is a whole section of Vagrant’s documentation on the subject.
I tried different things found on various forums over the Internet (such as this topic on Laracast) and, once I got it set up, the time per request dropped to around 1s.
This, you will agree, was quite an improvement.
If it originally required a few tweaks in Homestead's configuration, it turns out that with the recent versions of the box, almost all the work is already done.
The following is of course assuming that you are already using Homestead locally.
Note for Windows users: You may have noticed that the Vagrant documentation states that NFS is not available on Windows. If you are a PC user, you might want to have a look at Vagrant WinNFSd whose promise is to add support for NFS on Windows (I didn’t try it myself).
Note for Ubuntu users: You might need to install the NFS server:
apt-get install nfs-kernel-server
~/.homestead/Homestead.yaml, under the
folders section, add a
type option under the folders you wish to map using NFS, as such:
folders: - map: ~/Work/www/homestead to: /home/vagrant/projects type: "nfs"
Now, stop Homestead if it was running (
vagrant halt from
~/Homestead or however you usually do it) and start it again, forcing the provisioning step, e.g.:
vagrant up —-provision
You will be asked to enter your Mac OS user password before Vagrant mounts the folder(s).
You may wonder why isn't NFS activated by default, then: the reason is because it won't work out of the box on all operating systems, as seen in the notes above.