Shared folder in VirtualBox for Apache
Asked Answered
L

3

30

My host machine is ArchLinux and I'm running Apache in a CentOS guest. I have the vhost configuration and all the site code in a shared folder. To be able to put the vhost configuration in a shared folder I mounted the shared folder as apache:apache.

shared    /mnt/shared    vboxsf    defaults,uid=48,gid=48  0 0

When I'm editing files in the host, Apache will consistently start sending old versions of the file with trailing characters. In vim, they show up as ^@, so I guess they're null characters. The number of null characters is related to the number of changes I make even if I edit the first line, null characters show up at the end. If I were to speculate, it looks like a bad diff.

If I stop httpd, umount, remount, and start httpd the file looks fine. Just restarting httpd doesn't help.

How would I go about debugging the mount? Nothing jumped out at me in /var/log.

Laudian answered 9/6, 2011 at 20:37 Comment(3)
You can add permissions of vbox to apache2 : superuser.com/questions/335322/…Peppercorn
uid=48,gid=48 is what does that. It's not related to the problem I was having.Laudian
Possible duplicate of Vagrant/VirtualBox/Apache2 Strange Cache BehaviourFreestone
L
53

I was wrong; it was happening elsewhere but I noticed that it was only with .css and .js files. A search led me to this post which talks about a problem with vboxsf and small files.

The solution is to set, in Apache

    EnableSendfile off
Laudian answered 28/6, 2011 at 18:37 Comment(2)
This didn't work for me. However, if I open the file in vim on the VM and save it as-is, it will work after saving it on the VM. Any other ideas?Mowery
For completeness: in Nginx config it's "sendfile off;"Rachealrachel
W
1

On lighttpd the solution is to add the below line to lighttpd.conf

server.network-backend = "writev"

See: Lighttpd broken when serving from Virtualbox shared folder

Weathered answered 27/12, 2012 at 14:3 Comment(1)
YOU ARE A HERO!Caviness
W
0

To answer the specific question "how do I go about debugging the mount":

(the below is paraphrasing, based on an investigation I just did into a problem caused by the same bug in Virtualbox, but with a different web server)

After diagnosing the problem is happening somewhere in how Apache reads files inside the virtual host, I would use "strace -p" inside the virtual host to log system calls by Apache.

While stracing, request just the one truncated/corrupted file.

Careful diagnosis will reveal that it is correctly stat'ing the file to get its length. And then it is serving it using the sendfile syscall. Basically confirming sendfile is misbehaving, meaning it must be a bug in the virtual machine.

Searching for "sendfile virtualbox" takes you to these bugs.

https://www.virtualbox.org/ticket/9069 https://www.virtualbox.org/ticket/12597

Wolcott answered 5/11, 2014 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.