Mount Apache’s Web Directory Using Virtual Box Shared Folders

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:

Mount Shared Folder on Guest Machine

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:

1

more /etc/passwd

1

more /etc/group

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.

1

sudo vi /etc/rc.local

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