Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission issue in cache and logs folder in Symfony 2.0

Tags:

symfony

I have tried some ways to give permission to the cache & logs folder but whenever I clear cache at that time the problem occurs like unable to write in directory.

I have tried this two ways:

  1. Full access to cache via the root user with 777 permissions.
  2. Change the owner like www-data as said in Symfony2 docs.

but it didn't work for me.

like image 722
HVKotak Avatar asked Jul 17 '12 10:07

HVKotak


2 Answers

Solution:

Don't disable SELinux if you care about security if the site is global facing in anyway. In this case you would want to "Use" SELinux, not disable it, it's there for a reason.

I do this;

# chcon -R -t httpd_sys_script_rw_t /var/www/symfonyapp/app/cache
# chcon -R -t httpd_sys_script_rw_t /var/www/symfonyapp/app/logs
# apachectl restart #(or systemctl restart httpd) or (service restart httpd) to restart your server, a reboot will suffice as well.

And yes, @Viataley has one good point, now you need to check to make sure your web server user httpd, apache, or wwwdata is added to your users group, whatever group your user is in. This way when apache writes to the symfony directories that you user has recompiled through assetic when you run a cache clear for e.g., the g portion of the ugo which is your users group, will allow apache user permission to those dirs contents.

like image 67
blamb Avatar answered Oct 21 '22 21:10

blamb


If you do not want to turn off SElinux, here is a solution :

cd your/symfo/app
chcon -R -t public_content_rw_t app/cache
chcon -R -t public_content_rw_t app/logs
setsebool -P allow_httpd_anon_write 1
like image 27
Adrien LUCAS Avatar answered Oct 21 '22 21:10

Adrien LUCAS