Permission issue in cache and logs folder in Symfony 2.0

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

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.


Why it happens

The most common situation when such problem occurs - is when your web-server user does not have permission to write in the folder to which project belongs. Actually, changing the owner of app/cache and app/logs does not always help, because you may want to run some tests or console commands, which are executed from your user (php-cli/php-fpm). As result, cache or logs folder will be created from your current user and web-server user will not have access to it.

Solution

My proposition is either to add web-server user (which is probably www-data) to your user group or run web-server from your user - and you'll forget about such problem forever ;)

Similar problem, well-explained answer: Permissions issues on Symfony2

Tags:

Symfony