Solved – apache serving corrupted files via virtualbox vboxfs shares

TL;DR version: the 4.1 version of VirtualBox (or possibly more correctly, the VirtualBoxAdditions that provide the vboxfs) makes it impossible for Apache to correctly do its Kernel hand off, known as EnableSendfile. If you’re experiencing problems with files that are stored on a vboxfs share on your host not being served by Apache in your client, you need to find the EnableSendfile setting in httpd.conf and turn it OFF, and make sure you’ve installed/upgraded the version of the VirtualBox Additions that matches your VirtualBox version.

Virtualbox has to be one of the coolest free products out there for developers. We have a pretty hard core linux-based stack running AffinityLive, and for a full developer environment we need to have just the right setup of OS, libraries, code, apache, mysql, mongo, postfix, etc, etc, etc.

For our developers on Windows and Mac, trying to mirror this inside the O/S directly it almost impossible. While almost all of the constituent parts are there, the differences make it very unpleasant.

In the past we’ve “cheated” and used a shared dev server setup in the office, but it hurts the productivity of our team – every change to any code requires a save, commit with a message, then on the server side an update, and then potentially a Apache kick depending on how deep in the stack the change has been.

Enter Virtualbox. I spent a weekend at one point getting our production environment as cloned as possible into a CentOS client host, and mapped the bits we change a lot – our code – back to the host OS stored codebase, where programs like Eclipse are used to edit things. Now a developer just has to hit save on their local machine, and see the effect in their browser immediately; no more horrible triple handling. It means our staff can be more productive and take bigger risks, knowing if they bugger something up royally, they’re only going to piss themselves off, and not everyone else trying to work off a shared dev platform.

Then, this week, we had a problem. A bunch of the files that the Apache server in VBox hosts, which come from a file share on the host OS, were corrupted. CSS files with wacky binary content. Then, no images whatsoever. Losing our dev environment when things are so busy with the AffinityLive beta wasn’t an option – but unfortunately the solution took me almost a day to sort out, so I’m hoping this will help someone else save that time 😦

Step 1 – Update VirtualBox Additions

Virtualbox is a pretty actively maintained product, and recently they pushed version 4.1. What I didn’t realise every time I was saying “yes” to the upgrades is that I should also have been going through and upgrading the “virtualbox additions” – handy bits of functionality installed into the client OS.

The process for CentOS 5.5 clients on an underlying Windows host is:

  1. Start the client machine, and in the the window that shows you the machine booting/running, go to “Devices”, then “CD/DVD Devices” and then either VBoxGuestAdditions.iso and go to Step 3. If that option doesn’t exist, you’ll need to “Choose a virtual CD/DVD disk file” and continue onto Step 2 below.
  2. The ISO you need to choose will likely be located at “c:program filesoraclevirtualboxVBoxGuestAdditions.iso”. Choose that file, and hit save.
  3. Then, go into the shell of the VirtualBox, either by logging into the console window, or by SSH’ing through Putty, etc.
  4. If you didn’t log in as “root”, you’ll need to change to be the root user by running “sudo su -“
  5. Then run the following: “mount /dev/cdrom /mnt/cdrom”
  6. Then go into that directory – “cd /mnt/cdrom” – and run “./”.
  7. This will then go through and update the version of addons that you have running; it may take a few minutes to complete depending on how much memory and CPU you’ve allowed your client machine use.
Doing this was enough to make my CSS files, for example, not corrupted and broken, but then working CSS exposed another problem – images weren’t working.

Step 2 – Turning off Apache’s EnableSendFile handoff

Apache has a cool performance feature when it comes to serving up static content; rather than opening the files it is hosting itself, it passes the process of grabbing and opening the files down to the Kernel, saving double handling essentially.

Unfortunately, it looks like version 4.1 of VirtualBox breaks this, causing plain text files to be delivered down the line in a binary format, and causing binary images to be treated as “not found” because the file delivered doesn’t match the content length. Super frustrating.

The solution is pretty easy to implement – just turn off this feature in Apache.

Edit the httpd.conf file, for example, by running (as root, or prefixed with sudo) “vi /etc/httpd/conf/httpd.conf”

Find the directive where EnableSendFile is set to “on”.

Change the “on” to “off”.

Save the file out, and then restart Apache.

Step 3 – Restart the client machine & test it

This is more a precautionary step, but the Step 1 upgrade of the VBoxAdditions, you should restart your client machine, in this case the Linux box. The easiest way, in the console window, is to go to “Machine” and then “Close” and then “Send the Shutdown Signal”.

Once it shuts down, you can start it again the normal way.

Once it has booted up, you can test by loading up your site in Apache, and seeing if it worked.

Good luck, and if you continue to have problems (or these instructions solve it for you), let me know in the comments.

7 thoughts on “Solved – apache serving corrupted files via virtualbox vboxfs shares

  1. Howdy Geoff,
    It took me quite a bit of searching the interwebs before I found your solution to this problem. Thank you so very much.

    As a show of gratitude, I would like to make a donation to a non-profit entity of your choosing.

  2. Pingback: Why You Want to Develop in Production-Like Conditions, and How to Do it with Vagrant - Olivier Travers

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s