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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line