Reputation: 4633
I have a Symfony project in production and after running sudo php app/console cache:clear --env=prod
, the folder's permissions become
drwxr-xr-x 11 root root 4096 Feb 29 15:08 prod
This doesn't allow the user www-data
(apache default user) to access it anymore.
How can I clear the cache and have www-data read/write to the cache folder?
Also, running php console cache:clear
for the dev mode I get
The stream or file "../app/logs/dev.log" could not
and dev.log file has been created with following permissions:
be opened: failed to open stream: Permission denied-rw-r--r-- 1 www-data www-data 2840530 Feb 29 15:01 dev.log
Upvotes: 7
Views: 4685
Reputation: 1
Are you running console/bin as root? If you are running a long script but try :
chown -R webuser:webuser /var
If you enter the command directly , please
su webuser
Upvotes: 0
Reputation: 1071
See "Setting up Permissions" in http://symfony.com/doc/current/book/installation.html#configuration-and-setup.
If you use Ubuntu you can use setfacl
sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
EDIT:
$ rm -rf var/cache/* var/logs/* var/sessions/*
$ HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo chmod -R +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" var
$ sudo chmod -R +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" var
If there is no command setfacl on your pc you need install it;
sudo apt-get install acl
Upvotes: 8
Reputation: 34435
We run into the same problem, and we ended up running the cache:clear command as the Apache user.
The other option is to have a script run the cache clear command as sudo, and then reinitialise folder permissions.
Upvotes: -1