Reputation: 301
I am attempting to get to grips with vagrant and chef. If I download the opscode cookbook apache2 from git, checkout latest tag and do the following in my Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.forward_port 80, 8080
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "chef/cookbooks"
chef.add_recipe("apt")
chef.add_recipe("apache2")
chef.add_recipe("apache2::mod_rewrite")
end
end
...I end up with a VM with apache installed and working but (after some digging I found that) /var/www is not the documentroot it is infact /etc/apache2/htdocs
Do I need to add a line to my Vagrantfile to configure the document root?
Any help would be appreciated!
Guest Ubuntu 12.04
Upvotes: 3
Views: 2602
Reputation: 345
This solution fits in the Vagrantfile :
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :forwarded_port, host: 8080, guest: 80
config.vm.provision "chef_solo" do |chef|
chef.add_recipe "apt"
chef.add_recipe "apache2"
chef.json = {
"apache" => {
"default_site_enabled" => true,
"docroot_dir" => "/vagrant"
}
}
end
end
Doing this way you don't need to launch a site by SSH each time you "Vagrant up".
Upvotes: 6
Reputation: 301
I have found the solution and it was actually fairly basic, a cursory glance at the output during vagrant up gave the answer away.
[2013-08-25T14:30:51+00:00] INFO: execute[a2dissite default] sending restart action to service[apache2] (delayed)
By default apache disables the default site. ssh ing into the instance and running
sudo a2ensite default
sudo service apache2 restart
fixes things.
Looking at attributes/default.rb I found this line:
default['apache']['default_site_enabled'] = false
Now I am not sure on the best method for altering this attribute. (directly in this file? I doubt it)
Upvotes: 0
Reputation: 13920
It depends on your Linux distribution, for Debian/Ubuntu DocumentRoot defaults to /var/www
while for RHEL/CentOS/Oracle/Fedora/SUSE it defaults to /var/www/html
, for Arch Linux it defaults to /srv/http
.
Suppose you are using tag 1.7.0.
You can
default['apache']['docroot_dir']
in attributes/default.rbVagrantfile
(equivalent to node.js for a chef-solo run) to override the default values.NOTE: make sure you edit the right distribution related block
Upvotes: 1
Reputation: 21226
No. In Vagrantfile you configure your virtual machine (such as memory, hostname, ports) and recipes that should be run (in provision part). But changing apache document root requires changing the apache recipe. Check out the attributes/default.rb and change the required path.
Upvotes: 2