带有 Puppet 的 Vagrant 框的 Laravel 4 权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18648547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 Permissions on a Vagrant box with Puppet
提问by Adrian
I have been using http://www.puphpet.comsuccessfully to generate vagrant+puppet environments for a number of projects. Then this week I got tasked with writing a prototype for a project using Laravel 4. Since I'm not going to be the one working on the project full time, I figured it would be best to make a VM environment for it that the next person can just clone for the repo. Not having much experience with Laravel 4 I got everything to run in the dev environment just fine. Then I tried to run the first migration and here the problems start with the app/storage
file permissions.
我已经成功地使用http://www.puphpet.com为许多项目生成了 vagrant+puppet 环境。然后这周我的任务是使用 Laravel 4 为一个项目编写原型。由于我不会全职从事该项目的工作,我认为最好为它创建一个 VM 环境,以便下一个人可以为回购克隆。对 Laravel 4 没有太多经验我让一切都可以在开发环境中运行就好了。然后我尝试运行第一次迁移,这里的问题始于app/storage
文件权限。
1. app/storage must be writable by the web user
1. app/storage 必须是网络用户可写的
Fine, took out id: vagrant from the synced folder provisioning and set the owner & group to www-data like so:
好的,从同步文件夹配置中取出 id: vagrant 并将所有者和组设置为 www-data ,如下所示:
config.vm.synced_folder "./www", "/var/www", owner: "www-data", group: "www-data"
2. Artisan can only be run from inside the vagrant box to have access to the DB
2. Artisan 只能从 vagrant box 内部运行才能访问数据库
Fine, vagrant ssh
and run artisan from the www folder.
好的,vagrant ssh
然后从 www 文件夹运行 artisan。
3. app/storage & app/database have to be writable by the vagrant user in order to use migrations
3. app/storage & app/database 必须是 vagrant 用户可写才能使用迁移
Grrr, ok, added the following awful piece of code to the vagrant file (note, tried to do this in Puppet first and it didn't take):
Grrr,好吧,在流浪文件中添加了以下糟糕的代码(注意,首先尝试在 Puppet 中执行此操作,但没有成功):
config.vm.provision :shell, :inline =>
"usermod -a -G www-data vagrant"
4. app/storage & app/database are not writeable by the group
4. app/storage & app/database 不能被组写入
Argh!!! Ok, let's try this Puppet directive:
啊!!!好的,让我们试试这个 Puppet 指令:
file { "/var/www/app/storage":
source => "/var/www/app/storage/",
mode => 0775,
ensure => 'directory',
owner => 'www-data',
group => 'www-data',
recurse => true
}
Nope, doesn't work. Tried to do the same with the Puppet exec {}
directive to no effect. It seems that permissions for the vagrant synced folder are set by the host machine, not the guest.
不,不起作用。试图对 Puppetexec {}
指令做同样的事情,但没有效果。似乎 vagrant 同步文件夹的权限是由主机设置的,而不是来宾。
Finally ended up manually changing the permissions for the folder in the host machine. Is there any simpler way to do this? I would really just like to be able to give the next dev a worry free environment they can clone from the repo, not have them re-setup everything after cloning.
最后最终手动更改主机中文件夹的权限。有没有更简单的方法来做到这一点?我真的希望能够为下一个开发人员提供一个无忧的环境,他们可以从 repo 克隆,而不是让他们在克隆后重新设置所有内容。
UPDATE
更新
We've figured out that if we change the Apache run user, vagrant doesn't override it on reload. So we've done that manually and it's working better than changing the synced folder's permissions & owner. Now we're just trying to figure out how to make that change manually in Puppet.
我们已经发现,如果我们更改 Apache 运行用户,vagrant 不会在重新加载时覆盖它。所以我们手动完成了这件事,它比更改同步文件夹的权限和所有者更有效。现在我们只是想弄清楚如何在 Puppet 中手动进行更改。
回答by Adrian
After some discussion on Twitter, figured out the following:
在 Twitter 上进行了一些讨论后,得出以下结论:
There's a constraint from VirtualBox on vagrant that does not allow you to set permissions for the synced folder from inside the guest OS. See this issue on github.
VirtualBox 对 vagrant 有一个限制,不允许您从来宾操作系统内部设置同步文件夹的权限。在 github 上看到这个问题。
You can use the following code to set the synced folder permissionsfrom the vagrant file:
您可以使用以下代码从 vagrant 文件设置同步文件夹权限:
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
Or you can change the Apache runtime userto vagrant from the puppet manifest like so:
或者,您可以将 Apache 运行时用户更改为puppet 清单中的 vagrant,如下所示:
exec { "change_httpd_user":
command => "sed -i 's/www-data/vagrant/g' /etc/apache2/envvars",
onlyif => "/bin/grep -q 'www-data' '/etc/apache2/envvars'",
notify => Service['apache2'],
require => Package['apache2'],
}
file { "/var/lock/apache2":
ensure => "directory",
owner => "vagrant",
group => "vagrant",
require => Exec['change_httpd_user'],
}
Or any combination of the above
或以上任意组合
回答by Blessing
I'm not using pupphet in my setup and I came up with 2 solutions:
我没有在我的设置中使用 pupphet,我想出了 2 个解决方案:
(1) In my bootstrap.sh file:
(1) 在我的 bootstrap.sh 文件中:
sudo sed -i 's/APACHE_RUN_USER=.*/APACHE_RUN_USER=vagrant/g' /etc/apache2/envvars
sudo sed -i 's/APACHE_RUN_GROUP=.*/APACHE_RUN_GROUP=www-data/g' /etc/apache2/envvars
(2) Im my VagrantFile:
(2) 我是我的 VagrantFile:
config.vm.synced_folder "./", "/vagrant", id: "vagrant-root" , :owner => "vagrant", :group => "www-data"
config.vm.synced_folder "./app/storage", "/vagrant/app/storage", id: "vagrant-storage",
:owner => "vagrant",
:group => "www-data",
:mount_options => ["dmode=775","fmode=664"]
config.vm.synced_folder "./public", "/vagrant/public", id: "vagrant-public",
:owner => "vagrant",
:group => "www-data",
:mount_options => ["dmode=775","fmode=664"]
回答by Matt Setter
Have a look at this section of the Vagrant documentation http://docs.vagrantup.com/v2/synced-folders/basic_usage.html
查看 Vagrant 文档http://docs.vagrantup.com/v2/synced-folders/basic_usage.html 的这一部分