Getting Started with Vagrant for Local Development

Folder Syncing (vm.synced_folder): How to code with and change the box

Folder Syncing (vm.synced_folder): How to code with and change the box

Okay, so we have "synced" the ports between our computer and the virtual machine. What good is that if we can't access the files?

Syncing Folders

In a similar way that we "synced" our network, we're going to sync our folders:

config.vm.synced_folder '.', "/var/www"

The . in the example just means current directory. You can do anything you want, for example"

config.vm.synced_folder '../html', "/var/www/html"

It's really up to you on what you want synced. Check out the video demo to see it in action.


So this is nice that our files are synced, however you may run into permission issues. For example, the actual file permissions of your folders conflicting with the actual file permissions of the boxes.

I always do:

config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

You should probably do this too.

Tip of Iceberg

Just like "Networking", there's many, many additional options here. We won't walk through all of these, but I do want to show you one more thing.

NFS for Mac Users

If you're on a Mac, there's this thing called NFS (Network File System) to allow you to sync using a different protocol than the default VirtualBox shared folders implementation.

There's no difference to what you see, but there's a slight performance gain by doing this.

config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }

If you're on Windows, this is simply ignored.

Like this article? Follow @whatnicktweets on Twitter