If you got a permission denied on cache directory after/during deploy, make the following lines on your remote server :
sudo chown -R {whoami} {path/to/project}
sudo chmod -R 0777 {path/to/project}
Then, relaunch `cap production deploy``
| # Load DSL and set up stages | |
| require 'capistrano/setup' | |
| # Include default deployment tasks | |
| require 'capistrano/deploy' | |
| require 'capistrano/composer' | |
| require 'capistrano/symfony' |
| # config valid only for current version of Capistrano | |
| lock '3.4.0' | |
| set :application, 'portfolio' | |
| set :repo_url, '[email protected]:chalasr/sfPortfolio.git' | |
| set :ssh_user, "chalas_r" | |
| set :format, :pretty | |
| set :log_level, :info | |
| set :stage, "production" | |
| # Default branch is :master | |
| # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp | |
| set :deploy_to, "/var/www/html/projects/Portfolio" | |
| set :branch, "master" | |
| set :model_manager, "doctrine" | |
| set :pty, true | |
| # Default deploy_to directory is /var/www/my_app_name | |
| # set :deploy_to, '/var/www/my_app_name' | |
| # Default value for :scm is :git | |
| set :scm, :git | |
| set :symfony_env, "prod" | |
| set :app_path, "app" | |
| set :web_path, "web" | |
| set :log_path, fetch(:app_path) + "/logs" | |
| set :cache_path, fetch(:app_path) + "/cache" | |
| set :app_config_path, fetch(:app_path) + "/config" | |
| set :use_sudo, true | |
| set :permission_method, :chmod | |
| set :use_set_permissions, true | |
| set :writable_dirs, ["app/cache", "app/logs"] | |
| set :linked_dirs, %w{app/logs} | |
| set :keep_releases, 3 | |
| # Permissions | |
| set :file_permissions_paths, [fetch(:log_path), fetch(:cache_path)] | |
| set :file_permissions_users, ['www-data'] | |
| set :webserver_user, "www-data" | |
| # Assets | |
| set :assets_install_path, fetch(:web_path) | |
| set :assets_install_flags, '--symlink' | |
| namespace :deploy do | |
| task :check_permissions do | |
| on roles(:web) do | |
| execute "chmod -R 0777 #{release_path}/app/cache" | |
| execute "echo 'finished'" | |
| end | |
| end | |
| end | |
| after "deploy:finishing", "deploy:check_permissions" | |
| after "deploy:check_permissions", "deploy:finished" |
| source "https://rubygems.org" | |
| gem 'capistrano-rbenv' | |
| gem 'capistrano', github: 'capistrano/capistrano', branch: 'master' | |
| gem 'capistrano-symfony', :github => 'TheBigBrainsCompany/capistrano-symfony' | |
| gem 'capistrano-composer' |
| # server-based syntax | |
| # ====================== | |
| # Defines a single server with a list of roles and multiple properties. | |
| # You can define all roles on a single server, or split them: | |
| # server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value | |
| # server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value | |
| # server 'db.example.com', user: 'deploy', roles: %w{db} | |
| # role-based syntax | |
| # ================== | |
| # Defines a role with one or multiple servers. The primary server in each | |
| # group is considered to be the first unless any hosts have the primary | |
| # property set. Specify the username and a domain or IP for the server. | |
| # Don't use `:all`, it's a meta role. | |
| role :app, %w{[email protected]} | |
| role :web, %w{[email protected]} | |
| # role :web, %w{[email protected] [email protected]}, other_property: :other_value | |
| # role :db, %w{[email protected]} | |
| # Configuration | |
| # ============= | |
| # You can set any configuration variable like in config/deploy.rb | |
| # These variables are then only loaded and set in this stage. | |
| # For available Capistrano configuration variables see the documentation page. | |
| # http://capistranorb.com/documentation/getting-started/configuration/ | |
| # Feel free to add new variables to customise your setup. | |
| set(:latest_release, :deploy_timestamped ? release_path : current_release ) | |
| # Custom SSH Options | |
| # ================== | |
| # You may pass any option but keep in mind that net/ssh understands a | |
| # limited set of options, consult the Net::SSH documentation. | |
| # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start | |
| # | |
| # Global options | |
| # -------------- | |
| set :ssh_options, { | |
| keys: %w(/Users/Robin/.ssh/id_rsa), | |
| forward_agent: false, | |
| auth_methods: %w(publickey password) | |
| } | |
| # | |
| # The server-based syntax can be used to override options: | |
| # ------------------------------------ | |
| server 'dev.chalasdev.fr', | |
| user: 'chalas_r', | |
| roles: %w{web app}, | |
| ssh_options: { | |
| user: 'chalas_r', # overrides user setting above | |
| keys: %w(/home/chalas_r/.ssh/id_rsa), | |
| forward_agent: false, | |
| auth_methods: %w(publickey password), | |
| } |