Capifony和目录所有者 [英] Capifony and directory owners
问题描述
当我 cap deploy
我的Symfony2项目,然后登录到我的服务器,我看到,dev(app_dev.php)运行正常,但prod版本(app.php ) 才不是。
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.
错误是
[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
我可以用 chown修复问题-R www-data.www-data 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服务器由用户运行,谁不能写入刚刚创建的 cache / prod
目录。
This happens because your web-server is running by user, who is not able to write to just created cache/prod
directory.
有两个解决方案,我知道和使用。首先,在部署之后添加额外的命令以运行到 Capfile
。 Capfile将如下所示:
There are two solutions, which I know and use. First, add extra commands to run after deployment to Capfile
. Capfile will like this:
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/bundles/*/*/recipes/*.rb'].each { |bundle| load(bundle) }
load Gem.find_files('symfony2.rb').last.to_s
after "deploy:finalize_update" do
run "sudo chown -R www-data:www-data #{latest_release}/#{cache_path}"
run "sudo chown -R www-data:www-data #{latest_release}/#{log_path}"
run "sudo chmod -R 777 #{latest_release}/#{cache_path}"
end
load 'app/config/deploy'
第二个解决方案更加优雅。您指定正确的用户
,谁可以在 deploy.rb $ c中写入
缓存
$ c>并确保不使用sudo:
Second solution is more elegant. You specify correct user
, who can write to cache
in deploy.rb
and make sure that you don't use sudo:
set :user, "anton"
set :use_sudo, false
这篇关于Capifony和目录所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!