Skip to content

Instantly share code, notes, and snippets.

@joakim
Created January 25, 2011 14:00
Show Gist options
  • Save joakim/794940 to your computer and use it in GitHub Desktop.
Save joakim/794940 to your computer and use it in GitHub Desktop.
Using files from /vagrant as /var/www
# Create /var/www directory.
directory "/var/www" do
owner "www-data"
group "www-data"
mode "0755"
action :create
not_if "mountpoint /var/www" # Not if already mounted
end
# Mount /var/www directory.
mount "/var/www" do
device "/vagrant/www" # I keep my site files in a "www" subfolder, so I mount that
fstype "nfs"
options ["rw", "bind"]
action [:mount, :enable]
end
Vagrant::Config.run do |config|
(…)
# Share project folder through NFS.
config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
# Provisioning.
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe("vagrant_main")
end
(…)
end
@joakim
Copy link
Author

joakim commented Jan 25, 2011

Override of config.vm.share_folder to use NFS is recommended and (I think) required for the mount in default.rb to work.

@joakim
Copy link
Author

joakim commented Jan 26, 2011

UPDATE! Turns out the "mount --bind" technique used here gives horrible performance when many files are loaded, which is typical for CMS solutions, in my case Drupal. XHProf showed 2 (up to 3) times longer wall time with a bound mount compared to reading from the original /vagrant directory. You'll want to set your web server to fetch web files from the /vagrant directory instead.

@joakim
Copy link
Author

joakim commented Jan 26, 2011

A neat solution is to share the project folder through NFS to /srv on the box:

config.vm.share_folder("v-root", "/srv", ".", :nfs => true)

That way you can use /srv/www (being vagrant_project_dir/www), which is an alternative to /var/www in Linux. Just point your vhost files there, et voilà.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment