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
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.
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.
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}
I am deploying with
bundle exec cap staging deploy --trace
Thanks
UPDATE
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.
UPDATE
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
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
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