dongsicheng5262 2019-05-16 12:00
浏览 222

PHP-FPM可以创建slow.log但不能将内容写入slow.log

Today, I want to enable the slow-logs with PHP-FPM, and then I configured some parameters into the php-fpm.conf. In the end, I have a problem, it can create the slow-log, but can't write any contents into the slow-log. Can someone help me, thanks a lot?

My website is running in Docker, and my Nginx use Unix Sockets to communicate with PHP-FPM, and Nginx running as Root

location ~ \.php$ {
   try_files $uri =404;
   fastcgi_pass unix:/var/run/php-fpm7.sock;
}

My php-fpm.conf is

[www123]
user = app
group = app
listen = /var/run/php-fpm7.sock
listen.owner = app
listen.group = app
listen.mode = 0666

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

slowlog = /app/logs/my_slow_log/$pool.log.slow
request_slowlog_timeout = 1s

Next step, I created the directory app/logs/my_slow_log and restart the PHP-FPM. It created the file www123.log.slow in directory app/logs/my_slow_log, but the file permission/user/group is wrong. It was 600 / root / root

/app/logs/my_slow_log # ls -al
total 4
drwxr-xr-x    2 app      app             28 May 16 19:32 .
drwxrwxrwx    3 app      app           4096 May 16 19:00 ..
-rw-------    1 root     root             0 May 16 19:32 www123.log.slow

There are some running processes

app/logs/my_slow_log # ps -ef
PID   USER     TIME   COMMAND
    1 root       0:00 runsvdir /etc/service
    7 root       0:00 runsv nginx
    8 root       0:00 runsv javabridge
    9 root       0:00 runsv php7
   10 root       0:00 java -jar /usr/lib/jvm/java-1.8-openjdk/jre/lib/ext/JavaBridge.jar SERVLET_LOCAL:8080
   11 root       0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf -g daemon off;
   12 root       0:00 {php-fpm7} php-fpm: master process (/etc/php7/php-fpm.conf)
   13 root       0:00 nginx: worker process
   14 root       0:00 nginx: worker process
   15 root       0:00 nginx: worker process
   16 root       0:00 nginx: worker process
   22 app        0:00 {php-fpm7} php-fpm: pool www123
   23 app        0:00 {php-fpm7} php-fpm: pool www123

I find the master php-fpm process was run as Root, but the child process was run as app, so I modified the php-fpm.conf change

user = root
group = root
listen.owner = root
listen.group = root

then restart PHP-FPM, I got some error message

ERROR: [pool www123] please specify user and group other than root
ERROR: FPM initialization failed

It can't work as Root. I think the problem was /app/logs/my_slow_log/www123.log.slow created by PHP-FPM master process with root, and my child process was user app, so it can't write anything into the slow-log.

I didn't know what truly happened, can anybody help me? Thanks.

  • 写回答

1条回答 默认 最新

  • douwen7516 2019-05-16 12:27
    关注

    You can use this command (chmod 777 my_slow_log), I think Log directory permission is not important.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作