Using Vagrant with Symfony

Yesterday, the team received good news that the Vagrantfile for our development environment is ready. The team happily installed the Vagrant box and things looked fine, until this morning when some of us tried running the local tests.



This time round, we were pretty sure that this is not the result of the phantom bug. I had actually seen this error elsewhere before but it never bugged me enough for me to probe deeper into the cause of it. I used to be able to fix it by simply shifting the working folder from a shared folder into a non-shared folder. Therefore, it seems very likely that the cause of this problem is some file system conflict between the host and guest systems. Upon further research online, I found that other Symfony users also had the same problem running certain operations (such as rm -rf) on directories that are shared between the host and guest machines. Some of them observed that this problem usually happens when deleting directories with a large amount of files. They also observed that after a few tries of the same operation, the directory eventually gets deleted.

Since we know that the `rm -rf` operation first deletes recursive files and directories before deleting the root directory, we may postulate that the cause of this problem is due to the slow deletion of recursive files and directories under the root directory. Therefore, when the operating system returns to delete the root directory, it will find that some files are still not deleted and the operation to delete the root directory will fail as a result.

What worked for most users is to enable NFS (Network File System) for the shared folder. This will greatly speed up file operations and solve the problem that we're facing. For Mac users, enabling NFS for the shared folder is as simple as following the guide here. Windows 10, on the other hand, does not support NFS out of the box but not all hope is lost. I found a workaround for Windows 10 that involves installing the vagrant-winnfsd plugin. All you have to do is to run the command `vagrant plugin install vagrant-winnfsd` in your vagrant directory. Then, you may enable NFS for the shared folder as per the user guide on Vagrant. And voila, problem solved:


Now, we have not only solved the test issues but pages also get served faster due to speedier IO operations, thanks to the NFS.

Comments