HVKotak
HVKotak

Reputation: 258

Permission issue in cache and logs folder in Symfony 2.0

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.

Upvotes: 9

Views: 6674

Answers (6)

Rajesh Meniya
Rajesh Meniya

Reputation: 813

Temporary Solution:

Permanently disable SElinux

To permanently disable SElinux you need to edit SElinux's config file /etc/selinux/config and add/alter line disable it: SELINUX=disabled

Note: It's not safe to disable SElinux but for development environment it's ok.

Permanent Solution:

Good way to deal with permission issues is set permissions as per official guideline.

Upvotes: -2

blamb
blamb

Reputation: 4289

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.

Upvotes: 8

Adrien LUCAS
Adrien LUCAS

Reputation: 157

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

Upvotes: 7

Rajesh Meniya
Rajesh Meniya

Reputation: 813

Turn off SELinux security using following command as su user.

echo 0 > /selinux/enforce

Upvotes: -3

Vitalii Zurian
Vitalii Zurian

Reputation: 17986

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

Upvotes: 3

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44851

See the Setting up Permissions sidenote in the Configuration and Setup section. I recommend using the setfacl approach.

Upvotes: 2

Related Questions