Shared folders and Apache

Discussions about using Linux guests in VirtualBox.
Post Reply
ernstloeffel
Posts: 2
Joined: 10. Feb 2011, 13:16
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Fedora 14

Shared folders and Apache

Post by ernstloeffel »

I've spent hours but failed to figure out, why Apache can't access my shared folder.

Info:
Host System: Windows 7 / 32
Guest: Fedora 14 (minimal installation with LAMP)

What I tried so far:
- I've put the apache user to the vboxsf group
- I've disabled sendfile and mmap in httpd.conf (http://forums.virtualbox.org/viewtopic. ... ache#p6680)
- I've tried different ways to mount/automount the shared (http://forums.virtualbox.org/viewtopic.php?f=3&t=38315) folder, also tried to set file system flags (fmode=777, dmode=777). For an example I now use: mount -t vboxsf -o rw,uid=48,gid=500,fmode=777,dmode=777 share /var/www/html/sahred_folder
(uid 48 is apache and gid 500 is vboxsf)
- Chaned httpd.conf to start the daemon with user apache and group vboxsf
- Set Apache log level to debug... Still I only see "Permission denied" error... even though it should have access...

So of course I can see/use the folder from command line. But I have no clue why Apache isn't able to access the folder.
ernstloeffel
Posts: 2
Joined: 10. Feb 2011, 13:16
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Fedora 14

Re: Shared folders and Apache

Post by ernstloeffel »

I just also did change /etc/passwd to give user apache a shell. Then I logged in as apache and changed to the sahred folder and I see all files and folders...(but of course I still do get 403 in the browser) So I should now safely assume that my mount permissions are correct. So how should I figure what's causing the problem, probably between vboxsf file system driver and Apache settings...?
dishproductions
Posts: 2
Joined: 11. Mar 2011, 13:46
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu Server 9.10

Re: Shared folders and Apache

Post by dishproductions »

I'm having this same issue - I'm trying to make my Shared Folders my DocumentRoot in apache, but I'm getting a 403 Forbidden error in browser.

I ran a chown -R www-data:www-data /[sharedpath] but that didn't seem to change anything, also added the www-data user to the vboxsf group in the /etc/groups file, no luck.

I'm trying to get my HOST (win7) files to run in VBox apache server to view in HOST browser.

Anyone????
suomynona
Posts: 1
Joined: 14. Mar 2011, 03:03
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu Server 10.04.2

Re: Shared folders and Apache

Post by suomynona »

hi, i was getting frustrated with the same problem. i'm surprised i couldn't find the answer online. i'm glad the site moderators put so much time and effort into trying to help people out by answering forum posts, but sometimes i feel like they don't remember what it's like to be a n00b like me. they assume things are obvious when they're not. they probably look at a question like this and say to themselves, "it's obvious, read the virtualbox manual". yup, been there, done that, still failing :-p. sometimes the virtualbox manual isn't very clear for a n00b. but i suppose we all do it to a certain extent. anyway, here's my attempt at explaining what i did to get this working.

first of all, here is some background information:

Host OS (operating system installed on my computer): Windows 7 Enterprise (64-bit)
Guest OS (operating system installed in VirtualBox): Ubuntu Server 10.04.2 LTS (32-bit) (found at http://www.ubuntu.com/business/get-ubuntu/download)
VirtualBox Version: VirtualBox 4.0.4 for Windows hosts (found at http://www.virtualbox.org/wiki/Downloads)

ok, now for the overview of what i did (note that wherever i say go to "Devices" -> "something", you can also do that stuff under "Settings" in the VirtualBox Manager when the vm isn't running):
  1. create a new vm (virtual machine) and install Ubuntu Server 10.04.2 LTS using the iso downloaded from the ubuntu site linked above. (during software selection, i chose "LAMP server" and "OpenSSH server")
  2. log in to your fresh install using the credentials you specified during installation, then go to "Devices" -> "Install Guest Additions...". This should load the virtualbox guest additions iso into the cdrom drive of the vm
  3. then update ubuntu with the following code

    Code: Select all

    sudo aptitude update && sudo aptitude safe-upgrade
  4. as per instructions on the virtualbox manual (http://www.virtualbox.org/manual/ch04.html#id404776), install dkms. note that i will use aptitude instead of apt-get for everything. it doesn't matter which you use, i'm just more used to aptitude :-p.

    Code: Select all

    sudo aptitude install dkms
  5. mount cdrom (where the guest additions iso is loaded from step 2) to the cdrom folder (i use this folder since it is already created from the ubuntu install, so i don't have to make a new directory).

    Code: Select all

    sudo mount /dev/cdrom /cdrom
  6. go to where you mounted the cdrom and run the command that installs linux guest additions.

    Code: Select all

    cd /cdrom
    sudo sh ./VBoxLinuxAdditions.run
  7. go to "Devices" -> "Shared Folders..." to bring up the shared folders window. then click on the folder icon overlayed with a plus(+). click on the arrow by Folder Path and then click "Other...". now select a folder on your host machine that you want to share with the guest machine. take note of the Folder Name for later (you can also change it to whatever you want). then "OK" out of everything. DO NOT check "Read-only", "Auto-mount", and "Make Permanent". if you do, it will mount in a way where the permissions will be wrong and you'll get the 403 forbidden errors.
  8. now add your username (which you created when you installed ubuntu in step 1) to the vboxsf user group

    Code: Select all

    sudo nano /etc/group
    and then change the line

    Code: Select all

    vboxsf:x:1001:
    to

    Code: Select all

    vboxsf:x:1001:user
    where '1001' can be any number and 'user' is just the username you used to login to the system on step 2.
  9. now find the appropriate uid (user identifier) and gid (group identifier).

    Code: Select all

    sudo nano /etc/passwd
    and look for a line that looks like

    Code: Select all

    user:x:1000:1000:User,,,:/home/user:/bin/bash
    where, once again, '1000' can be and number and 'user' is the username you used to login to the system on step 2. the two numbers after 'x:' are the uid and gid you need to take note of. go ahead and exit out of your text editor without saving.
  10. now mount the shared folder.

    Code: Select all

    sudo mount -t vboxsf -o rw,uid=1000,gid=1000 test /var/www
    note that you should change the uid and gid number to whatever you found in step 9, 'test' to the folder name you chose in step 7, and '/var/www' to whatever folder you want to mount the shared folder to. also note that the folder you want to mount to should be created before you mount. so if you want to put it in /var/www/test, then

    Code: Select all

    sudo mkdir /var/www/test
    and then mount.
  11. check to see if it mounted correctly by creating something like test.html and putting it in your shared folders in windows. if you can open that page up in a browser through the virtual machine, then great!
  12. so if it's all working now, we need to get it to automount, so we don't have to run the mount command every time we start up the vm.

    Code: Select all

    sudo nano /etc/fstab
    and at the very bottom, add the line

    Code: Select all

    test /var/www vboxsf defaults 0 0
    where 'test' is the folder name you noted in step 7 and '/var/www' is where you want to mount to. go ahead and restart the vm.

    Code: Select all

    sudo shutdown -r now
    if you're still able to browse to the page you created in step 11 without mounting, then it should indicate that everything is working. w00t!
  13. OPTIONAL: go to "Devices" -> "Network Adapters..." and change Attached to: "NAT" to Attached to: "Bridged Adapter". this should make your vm look like any other computer on your network. then set up ubuntu with a static ip (once again, i use nano for my text editor, but you can use whatever you like. also note that the numbers you use will be based on your specific network).

    Code: Select all

    sudo nano /etc/network/interfaces
    and change

    Code: Select all

    auto eth0
    iface eth0 inet dhcp
    to

    Code: Select all

    auto eth0
    iface eth0 inet static
    address 192.168.1.123
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
    also be sure to change the port forward settings on your router if you wish to access your vm outside of your network.
  14. OPTIONAL: create a free account at http://www.dyndns.com/ and create a host. then install ddclient in ubuntu and configure it to update the host you created. more detailed instructions can be found here: https://help.ubuntu.com/community/DynamicDNS

    Code: Select all

    sudo aptitude install ddclient
    then after it's installed

    Code: Select all

    sudo nano /etc/ddclient.conf
    and add the following

    Code: Select all

    daemon=3600 
    ssl=yes
    and verify it's working with

    Code: Select all

    sudo ddclient -daemon=0 -debug -verbose -noquiet
    this will update your dyndns host every hour and you should now be able to access your vm webpages with an easy to remember url (somename.dyndns.org)
now that should do it. you should now be able to edit files directly in windows and have your vm serve it up to a browser. you should now also be able to use ssh/winscp to transfer files to the vm from a remote computer. sorry if this was long-winded, but i also wanted to document my process in case i ever need to look it up again. hopefully this helps some of you out. if you have any questions or comments, please feel free to post a reply. i'm sure there are probably easier ways to do things or things i'm not explaining very clearly. i'll check up on this post every once in a while for the next several days to respond to any posts if necessary.
dishproductions
Posts: 2
Joined: 11. Mar 2011, 13:46
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu Server 9.10

Re: Shared folders and Apache

Post by dishproductions »

Actually, I figured out my problem... I was doing an AutoMount of my Shared Folders - which mounts to a protected directory /media/sf_thefolder - instead I did the manual mount (mentioned in the previous post in this thread) to a directory I created under /var/www/mysite/ - and it worked!
shift8
Posts: 2
Joined: 24. Nov 2011, 04:07
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Fedora

Re: Shared folders and Apache

Post by shift8 »

First, thank you suomynona, because this was a SUPER super important post and the information was spot on.

It's also extremely important to note for guest OS' like Fedora that you most likely need to disable SELinux.

You can read more about how to do that here: http://docs.fedoraproject.org/en-US/Fed ... Linux.html

Also, you can add users to groups using the command line, usermod -G groupname username
That's a lot better/safer than going into the files under /etc...

In fact, if you just add apache and any other users you want to the vboxsf group (typically 1001 and you can find this out from looking in /etc/group) then you can mount your shared folder w/o specifying a gid and uid. For instance, right now because I didn't pass the -o option, my shared folder is mounted as root:root. Permissions are 777 on the files (I think probably always??). Apache is not in the root group...But despite the fact my shared folder says its root:root...Just belonging to the vboxsf group was enough to have the access.

You can also auto mount by editing (in Fedora and some other distros) /etc/rc.d/rc.local
If that file doesn't exist, at the top you'll want #!/bin/sh and ensure the file is executable (chmod +x) and then under that on a new line put the mount command, so something like:

Code: Select all

#!/bin/sh
mount -t vboxsf sharename /path/to/mount
That will auto mount your share on boot. You can also put it in fstab as described above.
The difference? I'm sure the rc.local runs after, but you should get a little more flexibility in the shell script there.
...though if you're trying to run Apache to server content from the mounted drive, you should use fstab. Otherwise the httpd service will fail to start on boot. Again, you could start the httpd service from rc.local ... but might as well do things the "right" way unless you have some strange requirement.
Post Reply