George Irimiciuc
George Irimiciuc

Reputation: 4633

Symfony cache:clear command changes folder owner

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
be opened: failed to open stream: Permission denied
and dev.log file has been created with following permissions: -rw-r--r-- 1 www-data www-data 2840530 Feb 29 15:01 dev.log

Upvotes: 7

Views: 4685

Answers (3)

Yang Guo
Yang Guo

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

Mert Öksüz
Mert Öksüz

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

David
David

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

Related Questions