简体   繁体   English

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

[英]How to set umask for php5-fpm on Debian?

I'm running php5-fpm with nginx connected via port (not socket). 我正在通过端口(而不是套接字)连接nginx运行php5-fpm It's stock Debian Jessie with all packages installed via apt-get . 它是Debian Jessie的现货,所有软件包都通过apt-get安装。

I'm trying to change default umask for www-data user that php5-fpm is using from 0022 to 0002 to allow group write permissions. 我正在尝试将php5-fpm使用的www-data用户的默认umask从0022更改为0002以允许组写入权限。 I've tried: 我试过了:

  • editing /etc/init.d/php5-fpm init script and adding --umask 0002 to the start-stop-daemon call, but it was ignored; 编辑/etc/init.d/php5-fpm初始化脚本,并将--umask 0002添加到start-stop-daemon调用中,但是被忽略了;
  • adding umask 0002 to /var/www/.profile as /var/www is a home directory for www-data user, but it didn't help (I'm not surprised). umask 0002添加到/var/www/.profile因为/var/wwwwww-data用户的主目录,但这没有帮助(我并不感到惊讶)。
  • I'm not using upstart so this solution is not for me. 我没有使用upstart因此此解决方案不适合我。

Also, no matter what I've tried, the command sudo -u www-data bash -c umask always returns 0022 . 另外,无论我尝试了什么,命令sudo -u www-data bash -c umask始终返回0022

I was able to set the umask for php5-fpm service by editing it's unit.service file as suggested here and here . 我可以按照此处此处的建议通过编辑它的unit.service文件来为php5-fpm服务设置umask。 The complete and working solution for Debian 8 is this: Debian 8的完整且有效的解决方案是:

  1. Manually edit /etc/systemd/system/multi-user.target.wants/php5-fpm.service file and add UMask=0002 line inside [Service] section. 手动编辑/etc/systemd/system/multi-user.target.wants/php5-fpm.service文件,并在[Service]部分中添加UMask=0002行。
  2. Run command systemctl daemon-reload 运行命令systemctl daemon-reload
  3. Run command systemctl restart php5-fpm.service 运行命令systemctl restart php5-fpm.service

Now the service file looks like this: 现在,服务文件如下所示:

[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

Note that: 注意:

  1. You can not use systemctl edit php5-fpm.service command as edit option was introduced in systemctl version 218 but Debian 8 ships with version 215. 您不能使用systemctl edit php5-fpm.service命令,因为在systemctl版本218中引入了edit选项,但是Debian 8随版本215一起提供。
  2. Adding *.conf file as suggested in comments for this answer did not work for me, but maybe I messed up something (comments are welcome for this as editing unit file is not something that I feel comfortable with). 添加*.conf文件作为该意见提出答案并没有为我工作,但也许我搞砸了的东西(的意见,欢迎此作为编辑部的文件不是东西,我觉得舒服)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM