大网数据广告活动
服务器运维问答

Make php-fpm log as root:adm

· 52CE 我爱测

I want to make sure members of the adm groups can read all logs, and the php-fpm process makes an exception as it logs php5-fpm.log under root:root and u=r+w I can't find a way to achieve this. I've considered using syslog.facili…

问题原文

原帖链接 · coolnodje · CC BY-SA 3.0

I want to make sure members of the adm groups can read all logs, and the php-fpm process makes an exception as it logs php5-fpm.log under root:root and u=r+w

I can't find a way to achieve this. I've considered using syslog.facility directives but I'd rather keep a dedicated log file.

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 4.0

You should read more carefully the manual on PHP FPM Configuration php-fpm.conf directives:

  • The syslog.facility directive only controls the facility type and is by default set to daemon. This doesn't affect the location. Non-normative syslog facilities are defined in RFC 5424, 6.2.1. As you can see, facilities 16-23 are for local use and you could dedicate one for PHP FPM.
  • The correct directive for sending log to syslogd instead of local file is error_log syslog, while the default value is #INSTALL_PREFIX#/log/php-fpm.log.
  • Another important directive here is syslog.ident php-fpm (that is the default value).

On configuration level there's nothing about file permissions. You'd have to get on the source code level to figure out how it's actually done. Some advice changing log file permissions on an init script.

One Logrotate to rule them all

File permissions can be controlled in logrotate configuration, which also has create directive.

/var/log/php-fpm.log {
    create 0640 root adm
}

Syslogd & dedicated facility

Using the Syslogd enables configuring all file locations on the same syslog.conf. It is still possible to configure syslogd to use separate log file for PHP FPM by the dedicated facility, e.g. local4:

# /etc/syslog.conf

local4.*    /var/log/php-fpm.log

Rsyslog filters

If you're using rsyslogd, you can filter the PHP-FPM's syslog.ident prepended to every message:

# /etc/rsyslog.conf

:syslogtag, isequal, "php-fpm"    /var/log/php-fpm.log
:syslogtag, isequal, "php-fpm"    ~

With rsyslogd, file permissions are also set in the rsyslog.conf:

# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。