在app / cache上设置perimissions而不用acl

时间:2013-09-11 16:41:22

标签: symfony permissions

我已将app/cache/目录权限设置为0775(文件到664)。和root的所有者:www-data。 这有效,但是当我清除缓存时,它将权限转为0755(文件为644),所有者为root:root。 它应该这样做:

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

    $ APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\  -f1`
    $ sudo chmod +a "$APACHEUSER 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

或者这个:

$ 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

但是acl在我的VPS中不起作用,我无法改变,因为它在这里说:serverfault question。 我在Symfony2文档中看到过这个:

Without using ACL

If you don't have access to changing the ACL of the directories, you will need to 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

Note that using the ACL is recommended when you have access to them on your server because changing the umask is not thread-safe.

问题是: 是否有更安全的方法可以在没有acl的情况下正确设置权限? umask用法是危险的吗?在这种情况下,“非线程安全”是什么意思?

1 个答案:

答案 0 :(得分:1)

唯一的方法是将您的cli用户(运行缓存清除命令的用户)设置为与Web服务器用户相同。在您的情况下,这意味着将此文件的所有者从root:www-data更改为www-data:www-data,并使用www-data用户运行cache clear命令。

关于umask,根据官方PHP文档:

  

避免在多线程Web服务器中使用此功能。最好在创建文件后使用chmod()更改文件权限。使用umask()可能会导致并发运行脚本和Web服务器本身的意外行为,因为它们都使用相同的umask。

希望有所帮助。