G
G
Greg Popov2016-07-30 18:36:20
htaccess
Greg Popov, 2016-07-30 18:36:20

How to set permissions for writing to a directory on a virtual machine under Vagrant?

Hello. There is a site, Yii2 framework, raised on vagrant + puphpet.
The problem is that assets and runtime are not being written to.
The Vagrantfile itself says:

Vagrant.configure('2') do |config|
  eval File.read("#{dir}/puphpet/vagrant/Vagrantfile-#{data['target']}")
  config.vm.synced_folder "./workspace", "/var/www", id: "vagrant-root", 
  :owner => "vagrant", 
  :group=>"www-data", 
  :mount_options=>["dmode=777,fmode=777"]
end

Neither through FileZilla nor through the console does it change the rights, what's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
werevolff, 2016-08-01
@werevolff

I use script for provision ansible. But bash can also be used. The crux of the matter is that the vagrant user has the ability to execute sudo commands without a password. Vagrant makes it possible to run bash code or an Ansible playbook. Conclusion: we create a bash file in which we write the chown and chmod commands to the required directories. Profit!!!

config.vm.provision, type: "shell", run: "always" do |s|
  s.path = "pdrovision.sh"
  s.privileged = false
  s.keep_color = true
end

And in provision.sh:
I can't vouch for the performance of vagrantfile with identical code, because everyone has their own approach here. I use .define with the declaration of the name of the virtual machine, the author's approach from the example is not clear. But the bottom line is to start provision by executing a bash script.
Another issue is that the operating system does not allow you to change the rights. But if it's a mac, then it should have chmod and chown commands in it. I understand that the projects are in the /some/path/to/Projects folder. The user of the system, let's say Vanya. From here, chown -R Vanya /some/path/to/Projects (on Mac) should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question