清除缓存时无法写入缓存文件“/var/www/myapp/app/cache/dev/classes.php”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8449345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to write cache file "/var/www/myapp/app/cache/dev/classes.php" when clearing the cache
提问by Omega
I have installed Symfony 2.0.7 on Ubuntu 11.10. I have this problem:
我已经在 Ubuntu 11.10 上安装了 Symfony 2.0.7。我有这个问题:
I changed the permissions of the cache
e logs
directories using the following commands:
我使用以下命令更改了cache
elogs
目录的权限:
chmod 777 -R cache
chmod 777 -R logs
and all functions as I was expecting.
和我期待的所有功能。
Then I made:
然后我做了:
app/console cache:clear
Clearing the cache for the dev environment with debug true
permissions of cache/dev change to 755 and symfony cannot write in that:
RuntimeException: Failed to write cache file "/var/www/myapp/app/cache/dev/classes.php".
in /var/www/myapp/app/bootstrap.php.cache line 1079 at ClassCollectionLoader::writeCacheFile() in /var/www/myapp/app/bootstrap.php.cache line 1017 at ClassCollectionLoader::load() in /var/www/myapp/app/bootstrap.php.cache line 682 at Kernel->loadClassCache() in /var/www/myapp/web/app_dev.php line 23
使用 debug true 清除开发环境的缓存
缓存/开发权限更改为 755 并且 symfony 无法写入:
运行时异常:无法写入缓存文件“/var/www/myapp/app/cache/dev/classes.php”。
在 /var/www/myapp/app/bootstrap.php.cache 第 1079 行中的 ClassCollectionLoader::writeCacheFile() 在 /var/www/myapp/app/bootstrap.php.cache 第 1017 行中的 ClassCollectionLoader::load() 中 / var/www/myapp/app/bootstrap.php.cache line 682 at Kernel->loadClassCache() in /var/www/myapp/web/app_dev.php line 23
How can I solve this apparent bug in Symfony 2?
我如何解决 Symfony 2 中这个明显的错误?
回答by Elnur Abdurrakhimov
See the Setting up Permissionssidenote in the Configuration and Setupsection. Use the ACL approach with setfacl
.
请参阅配置和设置部分中的设置权限旁注。将 ACL 方法与.setfacl
e.g.
例如
sudo setfacl -R -m u:apache:rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:apache:rwX -m u:`whoami`:rwX app/cache app/logs
(where apache
is your HTTPD user)
(apache
您的 HTTPD 用户在哪里)
回答by Federico Gallo
Well, I'm using setfacl
to avoid that issues but I still having problems.
I'm working on a standard user directoryso this do not work for me:
好吧,我正在使用setfacl
以避免这些问题,但我仍然遇到问题。
我正在处理标准用户目录,所以这对我不起作用:
APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
If you too, do this: (as privileged user if necessary of course )
如果你也这样做:(当然,如果有必要,作为特权用户)
sudo rm -rf app/cache app/logs
Then as NORMAL user create both directories and then apply the commands below as NORMAL user too (without sudo):
然后作为 NORMAL 用户创建两个目录,然后也以 NORMAL 用户身份应用以下命令(没有 sudo):
exit (from root if necessary)
mkdir app/cache app/logs
APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1`
setfacl -R -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
setfacl -dR -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
Note: remember that there are two spaces between -d\
and -f1
注意:记住-d\
和之间有两个空格-f1
Good luck!
祝你好运!
回答by Francis Alvin
In my case I just do as root user:
就我而言,我只是以 root 用户身份执行:
sudo -u apache app/console ca:cl
apache - this will vary depending on the owner your web directory. defaults to apache assuming you are using apache for your web server.
apache - 这将取决于您的 Web 目录的所有者。默认为 apache 假设您使用 apache 作为您的 Web 服务器。
回答by Rel van Keschnir
By looking at your posts I got to this page
通过查看您的帖子,我到达了此页面
http://symfony.com/doc/current/setup/file_permissions.html
http://symfony.com/doc/current/setup/file_permissions.html
Then I did this:
然后我这样做了:
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
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 setfacl -R -m u:"$HTTPDUSER":rwX -m u:whoami
:rwX var
sudo setfacl -R -mu:"$HTTPDUSER":rwX -mu: whoami
:rwX var
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:whoami
:rwX var
sudo setfacl -dR -mu:"$HTTPDUSER":rwX -mu: whoami
:rwX var
And it solved my problem
它解决了我的问题