Capistrano 3 权限在缓存和发布时未正确设置 [英] Capistrano 3 permissions not set on correctly on cache and releases
问题描述
我正在使用带有 Capistrano 3 将 Symfony2 Web 应用程序部署到 Ubuntu 14.04://github.com/capistrano/symfony" rel="nofollow">symfony gem.缓存文件夹的权限设置不正确:因为我正在使用 symfony gem 权限应该在缓存文件夹上设置,确实我在部署成功的输出:
I am deploying a Symfony2 web application onto Ubuntu 14.04 using Capistrano 3 with symfony gem. Permissions are not set correctly on the cache folder: Because I am using the symfony gem the permissions should get set on the cache folder and indeed I do see this in the output during deploy which is successful:
cd /var/www/releases/20151015083314 && ( SYMFONY_ENV=prod /usr/bin/env mkdir -pv app/cache
但是,当我预览 Web 应用程序时,我的日志中出现以下错误
However when I preview my web app i get the following error in my logs
PHP Warning: mkdir(): Permission denied in /var/www/releases/20151015082855/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/Store.php on line 40
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory (/var/www/releases/20151015082855/app/cache/staging)\n'
我在删除发布文件夹时也遇到了权限错误,但在我手动删除最旧的文件夹后,这似乎已经消失了.
I also got permissions errors when removing the releases folder but this seems to have gone away now after I manually removed the oldest folder.
我正在使用用户ubuntu"进行部署.我也尝试按照权限指南 here 使用ACL的第二种方法.我在/current 中的缓存文件夹和/shared 中的日志文件夹上设置了权限.
I am deploying with user 'ubuntu'. I have also tried to follow the permissions guide here using the second method of ACL. I set the permissions on the cache folder in /current and on the logs folder in /shared.
我的 capistrano 脚本如下:
My capistrano scripts have the following:
# deploy.rb
set :pty, true
set :ssh_options, {
user: 'ubuntu',
keys: ['~/.ssh/id_rsa'],
forward_agent: true,
auth_methods: ["publickey"]
}
set :linked_files, fetch(:linked_files, []).push('app/config/parameters.yml', 'web/.htaccess', 'web/robots.txt')
set :linked_dirs, fetch(:linked_dirs, []).push('app/logs', 'src/Helios/CoreBundle/Resources/translations', 'app/spool')
# staging.rb
server 'ec2-00-000-000-000.eu-west-1.compute.amazonaws.com', user: 'ubuntu', roles: %w{app db web}
我正在部署
bundle exec cap staging deploy --trace
谢谢
更新
奇怪的是,为什么 symfony2 应用程序尝试在/releases 而不是/current 中创建缓存文件夹?
what is strange is why does the symfony2 app try and create the cache folder within /releases rather than within /current ?
我也遵循了 本指南 如果我在部署后设置权限,但在全新部署后出现相同的缓存错误.
I also followed this guide which worked if I set the permissions after deploy, but then I got the same cache error after a fresh deploy.
更新
我再次检查了我的服务器,它作为 www-data 运行.我做了以下
I have checked again on my server and it it is running as www-data. I did the following
APACHE_USER=$(ps axho user,comm|grep -E "httpd|apache"|uniq|grep -v "root"|awk 'END {if ($1) print $1}')
echo $APACHE_USER
当我使用 capistrano 部署时,它无法删除旧的发布文件夹.对于无法删除的每个文件,我得到了多行:
When I deploy with capistrano it is unable to remove the old releases folder. I get multiple lines for each file it can't remove:
rm: cannot remove ‘20151029153350/app/cache/staging/.....’: Permission denied
用户 capistrano 正在按原样部署在 'www-data' 组中的 'ubuntu'.我已经检查了releases/20151029153350目录的权限,它是:
The user capistrano is deploying as is 'ubuntu' which is in the 'www-data' group. I have checked the permissions of the releases/20151029153350 directory and it is:
drwxrwxr-x 3 ubuntu ubuntu 4096 Oct 30 10:13 20151029153350
推荐答案
我建议您在 linked_dirs
中添加一个 app/cache
条目,然后创建shared/app/cache
并将其权限设置为 Web 服务器用户可以访问.通过这种方式,可以跨部署保留权限.
I'd suggest that you add to your linked_dirs
an entry for app/cache
and then create shared/app/cache
and set its permissions to be accessible by the web server user. This way permissions are retained across deployments.
或者,您可以使用此插件来设置已部署代码的权限.
Alternately, you could use this plugin to set permissions on the deployed code.
由于 /current
是 /releases/[release_timestamp]
的符号链接,一些代码会解析符号链接并直接访问它.
Since /current
is a symlink to /releases/[release_timestamp]
, some code will resolve the symlink and access it directly.
这篇关于Capistrano 3 权限在缓存和发布时未正确设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!