Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 452
George Irimiciuc Avatar asked Feb 29 '16 13:02

George Irimiciuc


1 Answers

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
like image 168
Mert Öksüz Avatar answered Nov 04 '22 22:11

Mert Öksüz