symfony2:写入缓存目录失败 [英] symfony2 : failed to write cache directory
问题描述
我不得不使用
app/console cache:clear command
解决生成实体时的问题.
to solve a problem when generating an entity.
我现在无法加载我的主页:
I am now unable to load my homepage on :
http://localhost/projet_etienne/web/app_dev.php
它说:
运行时异常:无法写入缓存文件/var/www/projet_etienne/app/cache/dev/classes.php".
RuntimeException: Failed to write cache file "/var/www/projet_etienne/app/cache/dev/classes.php".
我对缓存业务了解不多!
I don't understand much about this cache business!
在我的 app/cache
文件夹中,我有一个 dev
、一个 dev_new
和一个 dev_old
文件夹.正常吗?
In my app/cache
folder, I got a dev
, a dev_new
, a dev_old
folder. Is that normal?
app/console cache:clear
顺便生成一个:
[错误异常]警告:重命名(/var/www/projet_etienne/app/cache/dev,/var/www/projet_etien
ne/app/cache/dev_old):目录在/var/www/projet_etienne/vendo
中不为空r/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearComm
and.php 第 77 行
[ErrorException] Warning: rename(/var/www/projet_etienne/app/cache/dev,/var/www/projet_etien
ne/app/cache/dev_old): Directory not empty in /var/www/projet_etienne/vendo
r/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearComm
and.php line 77
请帮忙!
推荐答案
对于一个好的和明确的解决方案,请参阅安装和配置 Symfony
部分中的 设置权限
部分:
For a GOOD and definite solution see the Setting up Permissions
section in Installing and Configuring Symfony
section :
设置权限
安装 Symfony 时的一个常见问题是应用程序/缓存和app/logs 目录必须可由 Web 服务器和命令行用户.在 UNIX 系统上,如果您的 Web 服务器用户是与您的命令行用户不同,您可以尝试其中之一以下解决方案.
One common issue when installing Symfony is that the app/cache and app/logs directories must be writable both by the web server and the command line user. On a UNIX system, if your web server user is different from your command line user, you can try one of the following solutions.
- 对 CLI 和 Web 服务器使用相同的用户
在开发环境中,通常的做法是使用相同的CLI 和 Web 服务器的 UNIX 用户,因为它避免了任何设置新项目时出现这些权限问题.这可以是通过编辑您的 Web 服务器配置来完成(例如,通常httpd.conf 或 apache2.conf for Apache)并将其用户设置为与您的 CLI 用户相同(例如,对于 Apache,更新用户和组值).
In development environments, it is a common practice to use the same UNIX user for the CLI and the web server because it avoids any of these permissions issues when setting up new projects. This can be done by editing your web server configuration (e.g. commonly httpd.conf or apache2.conf for Apache) and setting its user to be the same as your CLI user (e.g. for Apache, update the User and Group values).
- 在支持 chmod +a 的系统上使用 ACL
许多系统允许您使用 chmod +a 命令.先试试这个如果出现错误 - 尝试下一个方法.这使用一个命令来尝试确定您的 Web 服务器用户并将其设置为 HTTPDUSER:
Many systems allow you to use the chmod +a command. Try this first, and if you get an error - try the next method. This uses a command to try to determine your web server user and set it as HTTPDUSER:
$ rm -rf app/cache/*
$ rm -rf app/logs/*
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
$ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
- 在不支持 chmod +a 的系统上使用 ACL
有些系统不支持 chmod +a,但支持另一个实用程序称为 setfacl.您可能需要在您的分区上启用 ACL 支持并在使用之前安装 setfacl(就像 Ubuntu 的情况).这个使用命令来尝试确定您的 Web 服务器用户并将其设置为HTTPDUSER:
Some systems don't support chmod +a, but do support another utility called setfacl. You may need to enable ACL support on your partition and install setfacl before using it (as is the case with Ubuntu). This uses a command to try to determine your web server user and set it as HTTPDUSER:
$ HTTPDUSER=`ps aux | 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 app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
对于 Symfony 3,它将是:
For Symfony 3 it would be:
$ HTTPDUSER=`ps aux | 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/cache var/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var/cache var/logs
如果这不起作用,请尝试添加 -n 选项.
If this doesn't work, try adding -n option.
- 不使用 ACL
如果前面的方法都不适合您,请更改 umask 以便缓存和日志目录将是组可写或全局可写的(取决于 Web 服务器用户和命令行用户是否在同组与否).为此,请将以下行放在app/console、web/app.php 和 web/app_dev.php 文件的开头:
If none of the previous methods work for you, change the umask so that the cache and log directories will be group-writable or world-writable (depending if the web server user and the command line user are in the same group or not). To achieve this, put the following line at the beginning of the app/console, web/app.php and web/app_dev.php files:
umask(0002); // This will let the permissions be 0775
// or
umask(0000); // This will let the permissions be 0777
请注意,当您可以在服务器上访问它们时,建议使用 ACL因为更改 umask 不是线程安全的.
Note that using the ACL is recommended when you have access to them on your server because changing the umask is not thread-safe.
来源:无法写入缓存文件/var/www/myapp/app/cache/dev/classes.php";清除缓存时
这篇关于symfony2:写入缓存目录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!