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.