Symfony 2缓存清除问题

ric*_*iot 12 caching cache-control symfony

我试图清除缓存时,我的Symfony 2网站最近给了我一些问题.我在终端中输入以下命令:

php app/console cache:clear --env=dev
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

[ErrorException]                                                                                                                                                                                                                                   
 Warning: rename(/var/www/corpsite/corpsite/app/cache/dev,/var/www/corpsite/corpsite/app/cache/dev_old): Directory not empty in /var/www/corpsite/corpsite/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php line 74  
Run Code Online (Sandbox Code Playgroud)

所以我将该文件的权限更改为777,并重新运行clear cache命令,这会给我这个错误:

  [ErrorException]                                                                                                                                                                                                                         
  Warning: unlink(/var/www/corpsite/corpsite/app/cache/dev_old/twig/6b/e9/4491e41b895786689b86f32f446f.php): Permission denied in /var/www/corpsite/corpsite/vendor/symfony/src/Symfony/Component/HttpKernel/Util/Filesystem.php line 100  
Run Code Online (Sandbox Code Playgroud)

我可以通过删除'dev_old'文件夹解决问题,但我想解决导致问题的问题.

PS - 我知道该网站正在开发模式下运行.该网站已经存在了10个月,这从来就不是问题.

任何帮助表示赞赏!

Hug*_*and 32

您需要获取缓存和日志文件夹的访问权限.为此,您可以按照此处给出的指示:http://symfony.com/doc/current/book/installation.html#configuration-and-setup

有几种方法,具体取决于您的操作系统(用您的apache用户替换www-data):

如果它支持chmod + a:

$ rm -rf app/cache/*
$ rm -rf app/logs/*

$ sudo chmod +a "www-data 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
Run Code Online (Sandbox Code Playgroud)

否则,如果它支持setfacl(请参阅https://help.ubuntu.com/community/FilePermissionsACLs):

$ sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
Run Code Online (Sandbox Code Playgroud)

另外,将这些行放在app/console的开头,web/app.php和web/app_dev.php(不推荐):

umask(0002); // This will let the permissions be 0775

// or

umask(0000); // This will let the permissions be 0777
Run Code Online (Sandbox Code Playgroud)