Vagrant and VirtualBox, modified files do not update when viewed in either NGINX or Apache

I recently got to grips with using Vagrant for web development. The VM environment I was able to create mirrors the one I created on our production servers at work. I also decided to go the whole-hog and create my own Debian Squeeze base box from scratch with the latest versions of VirtualBox Guest Additions, Ruby, OS updates etc. For a copy of it feel free to email me.

However, at the end of the process I encountered one problem. When I modified a file locally in the VirtualBox Shared Folder (/vagrant in the VM) and then loaded it through the web server (e.g. http://localhost:1337/css/styles.css) it would not show the changes I had made to the file. Instead I would just receive the old version of the file.

After some investigation and googling I discovered the problem is that VirtualBox’s Shared Folders do not fully support sendfile(). At the time of writing VirtualBox is on version¬†4.1.6.

The problem is easily fixed by disabling sendfile support in your HTTP server.
Apache:

EnableSendfile off

NGINX:

sendfile off;

sendfile() is an optimisation for reading and transmitting file contents. Disabling it within a development environment will not cause any compatibility issues and will only cause a completely negligible performance decrease. More information here.

6 thoughts on “Vagrant and VirtualBox, modified files do not update when viewed in either NGINX or Apache

  1. Thank you very much! I was having this exact problem and had yet to come up with a solution. Your’s worked perfectly!

  2. Oh my God!! This has been bugging me for days. I already destroyed and recreated my VM because I thought it was something that I have installed. Thank you! You’re a life saver.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>