Mount Apache’s Web Directory Using Virtual Box Shared Folders

By | November 30, 2015

It’s convenient to have a local web server where you can test changes to your website before uploading them to your live site, but how do you get your local web development files to the virtual web server? FTP or SSH? Constantly transferring files from the local host machine to the virtual server can take quite a bit of time. The better solution is to simply share the host’s web development directory with the guest LAMP server and then mount it to Apache’s /var/www directory.

This post explains how to setup a VirtualBox Shared Folder and mount it in the virtual server.

Guest Additions Installation

If you try to mount a VirtualBox Shared Folder without having installed Guest Additions, you’ll probably see the following error:

mount: unknown filesystem type ‘vboxsf’

VirtualBox Guest Additions must be installed before a VirtualBox Shared Folder can be mounted. You can install them by going to Devices ->  Insert Guest Additions CD Image in VirtualBox, or via the guest machine’s command line:

Configure the Shared Folder

From the Guest machine’s menu go to Devices -> Shared Folders -> Shared Folders Settings

Click the button with a plus sign on it and the “Add Share” window should appear.

Browse to the folder on your host machine that you wish to share, create a name for the share, and select the check boxes to make it auto-mount and permanent.

virtual_box_addshare

Mount Shared Folder on Guest Machine

Now we need to mount the share on the guest machine with a command similar to the following:

uid=1000,gid=1001 These two parameters set the owner and group of all files within the directory. Apache’s www-data user should be a member of whatever group you choose here.

Existing user and group IDs can be displayed by using the more command:

umask=0002 This gives the owner and group read, write and execute permissions while everyone else will have only read & execute permissions. See more about how to set a umask in Linux.

dmode=777 This gives everyone access to the directories within the mount point. Without this, if you are not the owner of the directory, you will get a ‘permission denied’ error when trying view the contents of it. For further information, search for ‘dmode’ on this VirtualBox forum thread.

Mount Share Automatically

Add the mount command you created to the /etc/rc.local file.

Whenever you restart the server, the share will be automatically mounted.

Additional Troubleshooting

You may need to make users members of the vboxsf group:

One thought on “Mount Apache’s Web Directory Using Virtual Box Shared Folders

Leave a Reply

Your email address will not be published.

*