3
votes

Here is the problem.

Cache stores in app/cache folder. I'm currently work under dev environment and my cache stores in app/cache/dev folder. Problem appears when I use symfony console comand for cache clearing:

php app/console cache:clear

when I try to load my project localhost/symfony/dev_app.php I receive an error:

RuntimeException: Failed to write cache file

I've installed setfacl extension, because Debian does not support chmod a+ and here is what I've done:

At first, I checked which user used when http requests performed:

ps aux | grep http

ahmed     7219  0.0  0.0   7552   884 pts/0    S+   19:51   0:00 grep http

Then I cleared app/cache folder by performing

rm -rf app/cache/*

Next step was:

setfacl -R -m d:u:ahmed:rwx,ahmed:rwx app/cache

As I understand, this command sets default permissions for user ahmed on app/cache folder and it current and new subfolders and files.

In my console I work under ahmed user.

After all this steps I loaded localhost/symfony/dev_app.php and cache was created. Then

php app/console cache:clear

And once again **ocalhost/symfony/dev_app.php* to create new cache. But I still receive this error

RuntimeException: Failed to write cache file "/var/www/local/symfony/app/cache/dev/classes.php".

So what am I doing wrong?

Here is the listing of getfacl for app/cache/dev

ahmed@ahmed:/var/www/local/symfony$ getfacl app/cache/dev
# file: app/cache/dev
# owner: root
# group: ahmed
# flags: -s-
user::rwx
user:ahmed:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:ahmed:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
1
I'm no expert with filesystem ACLs, but the Symfony book lists 2 commands. Did you run the second one as well (with -dR flags)? IIRC ACL must also be enabled on that partition.kgilden
yes, I did. I installed ACL correctly, set it for my partition in /etc/fstab, remounted it. Then I run that 2 commands. It does not help.Akhmed
Ah! But you're not setting ACL properly for the web server. The output of ps aux | grep http is returning you the grep process itself. The web server is likely running under a different name. Try grepping for apache or [a]apache to not list the search process itself.kgilden
I already did it too. user is same. Right now, I need to setup write permission for app/cache/dev, each time I clear the cache on consoleAkhmed
i don't believe, the apache runs under your user. should be www-dataEmii Khaos

1 Answers

5
votes

The web server group (probably www-data) needs to be able to write to the cache and so does your user. Your user (ahmed) should be a member of the www-data group (note that you will have to re-login for group membership to take effect). Setting the setgid bit (+s) on app/cache and app/logs will ensure that files and directories your user creates within those will maintain group ownership by www-data. Uncomment the umask(0002) line within app_dev.php so that files created by www-data will maintain group ownership, make sure YOUR user has a umask of 0002 (type umask at prompt to see, or umask 0002 to set, and google for help on setting this at login) and ensure that your permissions look something like:

    drwxrwsr-x 13 user www-data 4096 2013-05-10 11:05 dev

When your user ahmed creates files/directories within the directory owned by ahmed.www-data with +s, you should find that they are also owned by ahmed.www-data.