douwu0882 2015-08-27 13:21
浏览 92
已采纳

Symony2控制台命令删除缓存文件夹,更改权限

I have a few Symfony2 sites that I'm having problems regarding the cli user, and the cache directory.

CentOS 6.7 Apache 2.2.31 PHP 5.5.28 Symfony 2.7.1 (using Symfony3 dir structure)

I have followed the instructions on the Symfony2 installation guide, and I'm using the setfacl method to correctly set the permissions on the cache folder. As seen here (part 3):

http://symfony.com/doc/current/book/installation.html

On our server the http user is 'nobody'. I have added this to the portion of the script that determines the http user, that is ran before the actual change of permissions.

HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx|[n]obody' | grep -v root | head -1 | cut -d\  -f1`

Where things go wrong is when I'm logged in via ssh and I run the scripts to clear production cache:

php bin/console cache:clear --env=prod

What is happening if I run this command is that the cache folder is deleted, then it is 'warmed up' so the folder is recreated, but now I am the owner (not nobody), and the permissions on the directory are no longer set the same.

//Before (immediately after setting S2 permissions):
drwxrwsr-x+ 2 nobody   (group)  4096 Aug 27 08:00 cache/

//After running command and cache is warmed up:
drwxr-sr-x  6 (my SSH user)   (group)  4096 Aug 27 08:03 cache/

...or i run this...

php bin/console cache:clear --env=prod --no-warmup

If I run this command without the warmup, the cache folder is still deleted, but as soon as it gets some traffic, the cache folder is recreated, this time owned by nobody, but again the permissions are incorrect.

//Before (immediately after setting S2 permissions):
drwxrwsr-x+ 2 nobody   (group)  4096 Aug 27 08:07 cache/

//After running command and cache is rebuilt:
drwxr-sr-x  6 nobody   (group)  4096 Aug 27 08:10 cache/

This continuously causes problems for 'nobody' regarding not being able to create directories inside the cache folder. The only way I've found around it is to reset permissions on those folders after every single time the cache directory is recreated after clearing the cache.

It seems to me that the clear:cache commands should be deleting the contents of the cache directory, not the directory itself. Otherwise you have to reset the permissions every time you clear the cache. This just does not seem right to me.

Any help would be appreciated.

  • 写回答

2条回答 默认 最新

  • duanquezhan7268 2015-08-28 18:32
    关注

    To answer this question, user malcolm had guided me in the right direction that perhaps my directory structure wasn't correct. He was right in that. I had originally installed Symonfy2 with Composer using the Symfony3 Directory structure. After doing a minor symfony update I realized that the cache and log directories, were now back in the app folder like they would be in the old structure. So I added the scripts to the AppKernel.php file to point them back to the var folder, but neglected to provide the environment variable after the cache directory. So instead of deleting the 'dev' or 'prod' folder, the cache:clear commands were deleting the entire cache folder. Thanks for your help guys!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记