Question

I'm unable to access my Apache server within vagrant due to the file permissions and ownership of the /vagrant directory. How can I change the default owner and file permissions for /vagrant ?

The default permissions are as follows drwx------ 1 vagrant vagrant 4096 Apr 18 19:53 vagrant

What changes in the Vagrantfile can I make to override my default permissions?

Vagrant version 1.5.3

My Vagrantfile

Vagrant.configure("2") do |config|
    config.vm.provider :virtualbox do |vb|
    #...
    end
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
end
Was it helpful?

Solution 4

The issue has been temporarily resolved by changing the permissions on the host folder to 755 and then running a vagrant reload. I tried nearly every syntax for config.vm.synced_folder but to no avail. These commands in my vagrantfile appear to be ignored on vagrant up / reload.

OTHER TIPS

In Vagrant API version 2 you can share folders like so:

config.vm.synced_folder "/Direct/Path/To/Your/Folder", "/Direct/Path/To/The/Vagrant/Folder", :owner => "www-data", :group => "www-data"
config.vm.synced_folder "/Direct/Path/To/Another/Folder", "/Direct/Path/To/The/Other/Vagrant/Folder", :owner => "www-data", :group => "www-data"

You would place this information in the blocks after the following text:

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.

I had the same problem you are describing, and I fixed it via this method. Hope this helps. Any more information regarding this problem I highly recommend RT(F)M.

Here is one option I looked at when I tried to figure out how to do something similar:

config.vm.synced_folder "./sites", "/var/sites/", id: "vagrant-root",
  owner: "vagrant",
  group: "www-data",
  mount_options: ["dmode=775,fmode=664"]

To answer your question

What changes in the Vagrantfile can I make to override my default permissions?

None that I know of, more than what you have already noted.

To address the issue by altering the permissions on the host machine works. One way to do it is to make the synced folder group writeable with chmod -R g+w <synced folder>. Then in the vagrant VM add the apache server user (www-data on ubuntu) to the vagrant group with usermod -a -G www-data vagrant. The -a is very important, as this will append the new group to the list of groups for that user. If it is ommitted the new group replaces the old list.

You will also need to ensure that the umask on the vagrant VM is set to 0022, with umask 0022. And then restart the apache server.

You may also need to set the sticky bit on the synced folder in the host machine, with chmod -R +s <synced folder>.

I have to thank my colleague for giving me this answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top