Serving site through Apache via mounted folder

Discussions about using Linux guests in VirtualBox.
Post Reply
rsodhia
Posts: 10
Joined: 17. Oct 2016, 22:21

Serving site through Apache via mounted folder

Post by rsodhia »

I'm a webdev trying to learn more about server ops, which has led to me trying to learn more about Linux in general. I've been attempting to get a VirtualBox running with Ubuntu 14.04 (which matches my server) so I can do local development in something that more closely matches my live environment. After much stupidity, I finally got the networking working, and Apache is setup correctly, so I tried to mount the local folder where I have all my dev work onto Ubuntu. It mounts successfully, but when I try to hit the test site I created, I get:

Forbidden

You don't have permission to access / on this server.

An ops at work said this is a permissions issue, which makes sense, as the www folder that's created has different permission than the mounted folder does. But when I try to run chown to change the mounted folder's permission, nothing happens, which I'm led to believe, from web searching, that it's actually a mounted file system being treated as a folder, which is why it won't change ownership. I'm at a loss for how to to proceed. Is this a Virtualbox thing? A Linux/Ubuntu thing? Can I do what I'm trying to, or an impossible pipe dream?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Serving site through Apache via mounted folder

Post by Perryg »

Are you trying to use the auto-mount for the shared folder? Don't. Instead use the manual mount with options setting the user uid and gid then mount the share with /etc/rc.local.
rsodhia
Posts: 10
Joined: 17. Oct 2016, 22:21

Re: Serving site through Apache via mounted folder

Post by rsodhia »

Yup, using auto-mount. I guess time to go learn how to mount!
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Serving site through Apache via mounted folder

Post by Perryg »

Code: Select all

sudo mount -t vboxsf -o rw,uid=1000,gid=1000 <share name you used to create the share> <mount point>
Replace uid and gid with the uid and gid of the user that is running the guest and the <mount point> with the absolute path of the location that you use. I create a folder in /mnt to use as that would be the ( old fashioned ) proper place.

Then add the above statement to the /etc/rc.local about the exit line ( without the sudo ).
rsodhia
Posts: 10
Joined: 17. Oct 2016, 22:21

Re: Serving site through Apache via mounted folder

Post by rsodhia »

I'm sure I'm doing something stupid, but when I enter the command, I get this:

Code: Select all

sudo mount -t vboxsf -o rw,uid=33,gid=33 www /media/www
/sbin/mount.vboxsf: mounting failed with the error: No such file or directory
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Serving site through Apache via mounted folder

Post by Perryg »

The mount folder usually needs to be created so create one called www, but I really need to stress this that using /media will cause you issues.

Example: sudo mkdir /mnt/www
rsodhia
Posts: 10
Joined: 17. Oct 2016, 22:21

Re: Serving site through Apache via mounted folder

Post by rsodhia »

Thanks for clarifying that! Now I'm getting an Internal Service Error, but I assume that's because my server config is wrong/ini isn't correct. So thank you for helping me figure out the mounting part.

If you don't mind me asking, why would mounting to media be problematic? I assume by that you mean mounting to anywhere but mnt would be problematic. (VirtualBox's automount mounted to /mount/ so I figured it was fine.)
Martin
Volunteer
Posts: 2561
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: Serving site through Apache via mounted folder

Post by Martin »

Just be aware that others have tried to use a shared folder for Apache and were not successful because the shared folder implementation is missing many features like advanced file locking and access controls.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Serving site through Apache via mounted folder

Post by Perryg »

Using the auto-mount feature is the same as any removable media. Linux removable media permissions are very restricted as you saw when you tried to change them. The only way I got that to work was to manually mount after the and to change permissions there. That said Martin is correct that many people have failed shared folders with apache. Some believe this is because of lack of features and while some may be true I found that it was possible if you alter the permissions accordingly, at least as far as using them to serve up web pages. To your question about the /media and /mnt locations it is possible to use both but not so much for users new to Linux. Again if you have extensive knowledge with chown, chmod and how to use them anything is possible.
rsodhia
Posts: 10
Joined: 17. Oct 2016, 22:21

Re: Serving site through Apache via mounted folder

Post by rsodhia »

Thanks for all the feedback. I'll try to find some time in the next week to actually configure the server properly to serve the files. Other than mounting a shared folder, not sure if there are any other options for me to develop on my host machine (Windows) and test in a Linux environment, which would be ideal, given the differences between running Apache in Windows and Linux (and who wouldn't prefer developing in an environment as close to their production?). At work, we actually end up GIT pushing/pulling everything, which A) adds time, and B) makes testing really annoying. I've read that there is a windows driver for SSHFS, but that it can be problematic. Is there a better solution, or just the best of bad solutions?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Serving site through Apache via mounted folder

Post by Perryg »

Ah Windows host. You did not mention that earlier but I can tell you that this throws a huge wrench into the works. Windows permissions are extremely hard to get around in a Linux guest. They don't talk the same language. Yes it is possible but there is a lot more work evolved. Usually I suggest a true network share in this environment. Either bridged or an additional host-only should do it.
rsodhia
Posts: 10
Joined: 17. Oct 2016, 22:21

Re: Serving site through Apache via mounted folder

Post by rsodhia »

Eeer... maybe I'm not following? I currently have two adapters setup: a NAT to communicate with the external world, and a host-only to talk between host and guest. Can you share network files between Windows and Ubuntu/Linux? Even if it means a whole new line of learning, I figure it's worth it.

I'm sorry for all the stupid questions, as you can tell, I'm VERY new to this side of things. And I think ops at work is getting a bit annoyed at all my questions.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Serving site through Apache via mounted folder

Post by Perryg »

Can you share network files between Windows and Ubuntu/Linux?
Sure you can. Share the folder in Windows and then map the share in Linux. ( requires samba set up properly ) Mounting will still be the same but you will not use vboxsf.
Post Reply