When I deploy with Capifony a Symfony2 project I get this error message in apache log when accessing a webpage:
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to write cache file "/var/deploys/acme/releases/20150219150638/app/cache/prod/classes.php"
In order to avoid this, each time I deploy I have to execute chmod 777 -R cache
for fixing the permissions, which doesn't seem to me like a good solution.
The cache is set in the writable_dirs
option, so I don't know exactly why it gives a permissions error:
set :writable_dirs, ["app/cache", "app/logs", "app/sessions"]
I have the following deploy.rb configuration:
set :stages, %w(production staging)
set :default_stage, "staging"
set :stage_dir, "app/config"
require 'capistrano/ext/multistage'
set :application, "Api"
set :domain, "<my_domain>"
set :deploy_to, "/var/deploys/acme.com"
set :app_path, "app"
set :repository, "git@bitbucket.org:acme/api.git"
set :scm, :git
set :model_manager, "doctrine"
# Or: `propel`
role :web, domain
role :app, domain, :primary => true
set :keep_releases, 3
# Be more verbose by uncommenting the following line
logger.level = Logger::MAX_LEVEL
# Other options
set :user, "root"
set :use_sudo, false
# Symfony2 specific configuration
set :shared_files, ["app/config/parameters.yml"]
set :shared_children, [app_path + "/logs", web_path + "/uploads", "vendor"]
set :use_composer, true
set :update_vendors, true
set :writable_dirs, ["app/cache", "app/logs", "app/sessions"]
set :webserver_user, "www-data"
set :permission_method, :chown
set :use_set_permissions, true
set :assets_install, true
set :dump_assetic_assets, true
task :upload_parameters do
origin_file = "app/config/parameters.yml"
destination_file = shared_path + "/app/config/parameters.yml"
try_sudo "mkdir -p #{File.dirname(destination_file)}"
top.upload(origin_file, destination_file)
end
after "deploy:setup", "upload_parameters"
UPDATE
The cache folder has the following permissions when deployed:
drwxrwxrwx 3 root root 4096 Feb 20 13:13 cache
Inside the cache folder, a prod folder is also created with these permissions:
drwxrwxr-x 7 root root 4096 Feb 20 13:13 prod
UPDATE 2
I use root as user because in the server the user root has my public ssh key. If I set another user in the config, it asks me for root password when deploying. However I have set the webserver_user
variable in my config above. Also the user root it's not in the group www-data
, should it be?
My capifony version it's 2.8.3. Here is an example of command it executes when setting permissions if chmod_alt
is selected as settings permissions method:
getfacl --absolute-names --tabular ...
This error is also generated if I have chmod
as setting permissions method.
Although the previous command gives an error, I think the command that provokes the roll back (with chmod_alt
) is this one:
`echo stat /var/deploys/acme.devel/releases/20150226123037/app/sessions -c %U`
It generates the following error message (after which it makes a rollback):
cannot stat `/var/deploys/acme.devel/releases/20150226123037/app/sessions':
No such file or directory
I have set the following parameters in my deploy.rb in order to make it work:
set :use_sudo, true
default_run_options[:pty] = true
And I have removed app/sessions
from writable dirs option:
set :writable_dirs, ["app/cache", "app/logs"]