如何在 Debian 上为 php5-fpm 设置 umask?

How to set umask for php5-fpm on Debian?

我 运行 php5-fpmnginx 通过端口(不是套接字)连接。它是 Debian Jessie 的股票,所有软件包都通过 apt-get.

安装

我正在尝试将 php5-fpm 使用的 www-data 用户的默认 umask 从 0022 更改为 0002 以允许组写入权限。我试过:

此外,无论我尝试了什么,命令 sudo -u www-data bash -c umask 总是 returns 0022.

我能够通过按照建议 here and here 编辑它的 unit.service 文件来为 php5-fpm 服务设置 umask。 Debian 8 的完整且有效的解决方案是:

  1. 手动编辑 /etc/systemd/system/multi-user.target.wants/php5-fpm.service 文件并在 [Service] 部分内添加 UMask=0002 行。
  2. 运行命令systemctl daemon-reload
  3. 运行命令systemctl restart php5-fpm.service

现在服务文件如下所示:

[Unit]
Description = The PHP FastCGI Process Manager
After = network.target

[Service]
Type = notify
PIDFile = /var/run/php5-fpm.pid
ExecStartPre = /usr/lib/php5/php5-fpm-checkconf
ExecStart = /usr/sbin/php5-fpm --nodaemonize --fpm-config /etc/php5/fpm/php-fpm.conf
ExecReload = /bin/kill -USR2 $MAINPID
; Added to set umask for files created by PHP
UMask = 0002

[Install]
WantedBy = multi-user.target

注意:

  1. 您不能使用 systemctl edit php5-fpm.service 命令,因为 systemctl 版本 218 中引入了 edit 选项,但 Debian 8 附带版本 215。
  2. 按照评论中的建议添加 *.conf 文件 answer 对我不起作用,但也许我搞砸了一些东西(欢迎评论,因为编辑单元文件不是我的事感觉舒服)。