Capifony 和目录所有者
当我cap部署
我的Symfony2项目,然后登录到我的服务器时,我看到开发版本(app_dev.php)运行正常,但产品版本(app.php)运行正常。
错误是
[Tue Jan 03 14:31:48 2012] [error] [client xxx.xxx.xxx.xxx] PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to write cache file "/var/www/example/prod/releases/20120103202539/app/cache/prod/classes.php".' in /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache:1079\nStack trace:\n#0 /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache(1017): Symfony\\Component\\ClassLoader\\ClassCollectionLoader::writeCacheFile('/var/www/example/p...', '<?php ????name...')\n#1 /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache(682): Symfony\\Component\\ClassLoader\\ClassCollectionLoader::load(Array, '/var/www/example/p...', 'classes', false, false, '.php')\n#2 /var/www/example/prod/releases/20120103202539/web/app.php(10): Symfony\\Component\\HttpKernel\\Kernel->loadClassCache()\n#3 {main}\n thrown in /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache on line 1079
查看最近部署的缓存目录,我看到:
drwxrwxrwx 4 root root 4096 Jan 3 14:28 .
drwxrwxr-x 5 root root 4096 Jan 3 14:28 ..
drwxr-xr-x 6 www-data www-data 4096 Jan 3 14:28 dev
drwxrwxr-x 7 root root 4096 Jan 3 14:28 prod
我可以使用 chown -R www-data.www-data prod/ 修复问题,但我想知道是否可以阻止这种情况在首位?为什么这些目录有不同的所有者?
When I cap deploy
my Symfony2 project, then log into my server I see that the the dev (app_dev.php) runs ok but the prod version (app.php) does not.
The error is
[Tue Jan 03 14:31:48 2012] [error] [client xxx.xxx.xxx.xxx] PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to write cache file "/var/www/example/prod/releases/20120103202539/app/cache/prod/classes.php".' in /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache:1079\nStack trace:\n#0 /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache(1017): Symfony\\Component\\ClassLoader\\ClassCollectionLoader::writeCacheFile('/var/www/example/p...', '<?php ????name...')\n#1 /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache(682): Symfony\\Component\\ClassLoader\\ClassCollectionLoader::load(Array, '/var/www/example/p...', 'classes', false, false, '.php')\n#2 /var/www/example/prod/releases/20120103202539/web/app.php(10): Symfony\\Component\\HttpKernel\\Kernel->loadClassCache()\n#3 {main}\n thrown in /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache on line 1079
Looking at the recently deployed cache directory I see:
drwxrwxrwx 4 root root 4096 Jan 3 14:28 .
drwxrwxr-x 5 root root 4096 Jan 3 14:28 ..
drwxr-xr-x 6 www-data www-data 4096 Jan 3 14:28 dev
drwxrwxr-x 7 root root 4096 Jan 3 14:28 prod
I can fix the issue with chown -R www-data.www-data prod/
but I wondered if I can stop this from happening in the first place? And why do the directories have different owners?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
发生这种情况是因为您的网络服务器由用户运行,该用户无法写入刚刚创建的
cache/prod
目录。我知道并使用两种解决方案。首先,添加额外的命令以在部署到
Capfile
后运行。 Capfile 会喜欢这样:第二种解决方案更优雅。您指定正确的
用户
,该用户可以写入deploy.rb
中的缓存
,并确保您不使用sudo:This happens because your web-server is running by user, who is not able to write to just created
cache/prod
directory.There are two solutions, which I know and use. First, add extra commands to run after deployment to
Capfile
. Capfile will like this:Second solution is more elegant. You specify correct
user
, who can write tocache
indeploy.rb
and make sure that you don't use sudo:在 capifony 的最新版本中,他们添加了设置可写目录的选项。
这是官方文章,解释了我在下面写的内容: http://capifony.org/cookbook/ set-permissions.html
您必须使用 sudo 进行部署(不是一个好的做法,但它可以完成工作)
并告诉 capifony 哪些文件使缓存和日志文件夹可写:(
您必须在你的机器,或者使用 :chwon 而不是 :acl)
编辑 :
我刚刚意识到这还不够,“set_permissions”任务不会自动调用,所以你必须显式运行
或在你的deploy.rb中添加这一行:
In the last version of capifony, they've added the option to set writable directories.
Here's the official article which explains what I've written below : http://capifony.org/cookbook/set-permissions.html
You have to deploy using sudo (not a good practice, but it gets the job done)
and tell capifony which files to make cache and logs folder writable :
(you have to install acl on your machine, or use :chwon instead of :acl)
EDIT :
I've just realized that this is not enough, the "set_permissions" task is not automatically called, so you have to explicitly run
Or add this line in your deploy.rb :
我通过将缓存文件夹添加到共享文件夹解决了这个问题。
这样部署时每次都不会重新创建目录,所以不存在权限问题。
I solved this problem by adding cache folder to shared folders.
This way the directory is not recreated each time during deployment, so there is no problem with permissions.
是的,不需要每次部署后重新创建缓存,这个解决方案是合乎逻辑且实用的。
Anton 的第二个解决方案 - 如果您在开发环境中缓存文件夹权限为 true,则可以使用
Yes, don't need recreate cache every time after deploy, this solution is logical and pragmatical.
Second solution from Anton - is work if you cache folder permission true in develop environment