Shared folders and Apache
-
- 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
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.
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.
-
- 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
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...?
-
- 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
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????
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????
-
- 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
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):
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):
- 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")
- 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
- then update ubuntu with the following code
Code: Select all
sudo aptitude update && sudo aptitude safe-upgrade
- 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
- 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
- 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
- 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.
- now add your username (which you created when you installed ubuntu in step 1) to the vboxsf user groupand then change the line
Code: Select all
sudo nano /etc/group
toCode: Select all
vboxsf:x:1001:
where '1001' can be any number and 'user' is just the username you used to login to the system on step 2.Code: Select all
vboxsf:x:1001:user
- now find the appropriate uid (user identifier) and gid (group identifier).and look for a line that looks like
Code: Select all
sudo nano /etc/passwd
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.Code: Select all
user:x:1000:1000:User,,,:/home/user:/bin/bash
- now mount the shared folder.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 mount -t vboxsf -o rw,uid=1000,gid=1000 test /var/www
and then mount.Code: Select all
sudo mkdir /var/www/test
- 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!
- 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.and at the very bottom, add the line
Code: Select all
sudo nano /etc/fstab
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
test /var/www vboxsf defaults 0 0
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!Code: Select all
sudo shutdown -r now
- 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).and change
Code: Select all
sudo nano /etc/network/interfaces
toCode: Select all
auto eth0 iface eth0 inet dhcp
also be sure to change the port forward settings on your router if you wish to access your vm outside of your network.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
- 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/DynamicDNSthen after it's installed
Code: Select all
sudo aptitude install ddclient
and add the followingCode: Select all
sudo nano /etc/ddclient.conf
and verify it's working withCode: Select all
daemon=3600 ssl=yes
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)Code: Select all
sudo ddclient -daemon=0 -debug -verbose -noquiet
-
- 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
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!
-
- 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
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:
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.
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
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.