Created
January 25, 2011 14:00
-
-
Save joakim/794940 to your computer and use it in GitHub Desktop.
Using files from /vagrant as /var/www
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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.
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
Override of config.vm.share_folder to use NFS is recommended and (I think) required for the mount in default.rb to work.