How do I set the Apache2 DocumentRoot to a "vboxsf" VirtualBox Shared Folder? (permissions issue?)

17

10

I setup Ubuntu 11.04 desktop 32 bit on a VirtualBox VM with a shared folder to the host. The shared folder is

/media/sf_Dev/

I want to change Apache2 to point the DocumentRoot to that folder, so I edited /etc/apache2/sites-available/default to replace the existing two paths in that file to /media/sf_Dev/ instead of /var/www and it won't show index.html.

When I look at /var with ls -l I see

drwxr-xr-x  2 root root ... www

and when I ls -l /media/ I see

drwxrwx---  1 root vboxsf ... sf_Dev

and Apache doesn't seem to see the index.html I put in that directory (cp /var/www/index.html /media/sf_Dev/ iirc)

I also tried editing envvars to make the group be vboxsf but I think I did that part wrong.

export APACHE_RUN_GROUP=www-data

to

export APACHE_RUN_GROUP=vboxsf

What am I doing wrong, what do I need to do to get Apache2 to serve files from that directory? (technically I want to serve files for apache from /media/sf_Dev/apache/www but I figure one step at a time, so if that helps you short-circuit things, so be it)

jcolebrand

Posted 2011-09-14T04:46:22.233

Reputation: 1 020

Answers

22

It would probably be easiest to add the vboxsf group as a supplementary group for apache.

Ubuntu:

sudo usermod -a -G vboxsf www-data

Fedora:

sudo usermod -a -G vboxsf apache

This does it for me when I want to access auto mounted shared folders. You might also want to add your own username to the vboxsf group to access the files.

Fuu

Posted 2011-09-14T04:46:22.233

Reputation: 580

This solution fixed it for me on Ubuntu 15. Many thanks! – Ian Lewis – 2015-11-04T12:53:37.660

But is the apache app running under the username apache? I thought that changed >.> – jcolebrand – 2011-09-16T21:42:22.337

You're correct, I mixed the apache user for fedora and ubuntu. edited :) – Fuu – 2011-09-16T23:23:36.197

1Saved me a bunch of time fiddling around with manual mounting.. thanks! – xorinzor – 2013-07-07T15:57:01.443

3

That looks like a permissions issue. You'll need read and execute permission on /media/sf_Dev/ for "other" (the third group of permission bits, which are currently no permissions or ---).

So, you'll need to run this command (since it's Ubuntu, note the sudo):

sudo chmod 775 /media/sf_Dev/

That will add read and execute for "other" and leave full permissions for owner and group.

Also make sure that the index file actually exists in /media/sf_Dev/. (I'll assume that you forgot the sudo in the cp command and that you're not running as root.)

George Marian

Posted 2011-09-14T04:46:22.233

Reputation: 143

1Ahhh, but when I do that it doesn't make the changes I need. Something about the vboxfs doesn't let those changes get made (ie: like NFTS) ... oooh, which may be the problem, the files are originally hosted on NTFS (since it's a windows host) so I don't think I can do that. ~~ I had forgotten to look at the errorlog before asking. I shall check that this evening. However, assume it's a permissions error. – jcolebrand – 2011-09-14T15:48:15.693

@jcolebrand Rule #1 of troubleshooting: is it plugged in? Nevermind that I'm thinking about the long term usefulness of the answer and that I know you as a DB and .NET guy. :P – George Marian – 2011-09-14T21:14:57.987

@jcolebrand So, silly question: Did you restart apache? sudo apache2ctl restart – George Marian – 2011-09-14T21:16:06.597

hahahahaha, this is why I need help, I'm a db and .net guy ;) ... yeah, I actually dropped into sudo su once it started being a wench so I could go into all the directories and see what was "broken" ... I'm gonna do what Josh suggested later with the PHP file. – jcolebrand – 2011-09-14T21:16:09.733

I did a graceful, not a restart. Big difference? Also, tonight it'll have a cold-restart (VM, full shutdown both boxes) – jcolebrand – 2011-09-14T21:16:38.237

@jcolebrand Well, there are some differences. On a dev system, I would use restart. There is no reason to (potentially) complicate things by using graceful: http://httpd.apache.org/docs/2.0/stopping.html

– George Marian – 2011-09-14T21:41:15.967

1It is possible that vboxsf does not support setting permissions for the root folder of file system and it may provide mode, uid and gid mount options to set file permissions globally. – billc.cn – 2011-09-17T01:58:38.047

2

You didn't say what the specific error was, only

and Apache doesn't seem to see the index.html I put in that directory

The specific error would help. You can file this in Apache's error_log, which is typically under /var/log/apache2/error.log under Ubunt, but can be configured via an ErrorLog Directive in your <VirtualHost>

Without the actual error, I assume George Marian is correct and it's a permissions error. You can check to see what group Apache is running under using:

ps -o pid,group -o atime,comm=CMD awx | grep apache

Try chainging permissions on /media/sf_Dev/ as he said.

I think you may better off handling this with an Alias directive as that will allow you to make only certain parts of your DocumentRoot point to locations outside:

Alias /info /media/sf_Dev
<Directory /media/sf_Dev >
  Order allow,deny
  Allow from all
</Directory>

EDIT: If the Apache server has mod_php (not FastCGI PHP) and is not using suexec, you can determine if Apache is running under the proper GID (group ID) with the following PHP snippit:

<?php

var_dump(posix_getegid());

Make sure that returns the same GID as vboxsf. (You can find the GID for vboxsf in /etc/groups)

Josh

Posted 2011-09-14T04:46:22.233

Reputation: 7 540

I had forgotten to look at the errorlog before asking. I shall check that this evening. However, assume it's a permissions error. See my response to George above – jcolebrand – 2011-09-14T15:50:18.953

OK. Then we should focus on getting Apache to run as GID vboxsf. Can you edit and post the relevant parts where you changed the Group? – Josh – 2011-09-14T15:53:24.957

I edited one line in envvars, and it said group, but I'm not looking at the box right now. – jcolebrand – 2011-09-14T15:54:22.350

0

If you have configured the shared folder to be auto mounted. Then you need to first disable the same and mount the shared folder manually. If you need automount it every time you start the vm, you need to add respective entry inside your /etc/fstab. (It seems there is some issue mounting vbox shared folder through fstab. So adding below mentioned command inside /etc/rc.local worked for me to mount it on start).

Load Shared Folder with Correct User / Group

As far as I can tell, this error is due to the owner and group of the shared folder. Apache expects the files to render to belong to the group www-data. By default, however, the shared folder in VirtualBox belongs to the vboxsf user. We will add this user to the www-data group. To do so, edit the group properties on the guest:

sudo usermod -a -G vboxsf www-data

We’ll now mount the shared folder and assign it to the www-data user and group. To check out the user and group id, you can have a look at the /etc/passwd file on the guest machine (cat /etc/passwd | grep 'www-data'). On Debian based OS, both ids are usually set to the value 33. So, simply issue the following command on the guest:

mount -t vboxsf -o rw,uid=33,gid=33 website /media/sf_website

Note that website is the name of the shared folder (as illustrated in the screenshot above) and /media/sf_website is where the folder will be mounted.

Fore more details refer this link http://jimmybonney.com/articles/configure_virtualbox_shared_folder_apache_virtual_host/

Pandurang Patil

Posted 2011-09-14T04:46:22.233

Reputation: 111