Greetings,
This is what I've been struggling with for a while now.
I was wondering maybe somebody has experience with this.
So I have php 8.1.23 and nginx 1.24.0 installed from ports. Then I use php-fpm as fastcgi service to communicate with nginx.
Everything works perfectly, but errors reporting, which drives me crazy.
What I'm trying to achieve is I want to combine PHP and nginx errors in a single log file. So, instead of php-fpm using separate log files (or syslogd) I want it to send logs back to nginx so nginx can store PHP error logs within nginx error log files.
I saw some examples online, they look something like this:
1. An example of PHP code that triggers an error
2. Nginx's error log file
I did the following configuration for nginx and php-fpm, it looks like this is what people use in general to achieve my goal.
This is not working for me.
At the beginning of my journey, I was confused about how nginx actually gets this information and thought it magically happens through STDERR descriptor from php-fpm to nginx, but then I did some digging into the FastCGI protocol, and it looks like backend (php-fpm) actually can send this information using FCGI_STDERR record type.
After the finding, I started to dump traffic between nginx and php-fpm, so I discovered that php-fpm is not sending FCGI_STDERR back to nginx when an error on the PHP side happens.
I checked docs of php-fpm configuration a couple of times and haven't found how to allow/force send this FCGI_STDERR back to nginx explicitly.
At this point, I'm completely lost.
This is probably not the best place to ask this kind of question, but I was wondering if this is somehow related to how php configures/complies from ports.
Will appreciate any help
This is what I've been struggling with for a while now.
I was wondering maybe somebody has experience with this.
So I have php 8.1.23 and nginx 1.24.0 installed from ports. Then I use php-fpm as fastcgi service to communicate with nginx.
Everything works perfectly, but errors reporting, which drives me crazy.
What I'm trying to achieve is I want to combine PHP and nginx errors in a single log file. So, instead of php-fpm using separate log files (or syslogd) I want it to send logs back to nginx so nginx can store PHP error logs within nginx error log files.
I saw some examples online, they look something like this:
1. An example of PHP code that triggers an error
PHP:
<?php error_log("MESSAGE", 0);?>
Code:
2020/06/04 16:23:00 [error] 9057#9057: *26 FastCGI sent in stderr: "MESSAGE" while reading response header from upstream, client: 151.24.155.27, server: "fqdn", request: "GET /page.php HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1"
I did the following configuration for nginx and php-fpm, it looks like this is what people use in general to achieve my goal.
Code:
server {
...
access_log /var/log/nginx/domain.access_log main ;
error_log /var/log/nginx/domain.error_log error ;
...
location ~ \.php$ {
try_files $uri =404 ;
fastcgi_intercept_errors off ;
fastcgi_buffering off ;
fastcgi_request_buffering off ;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params ;
}
...
}
Code:
[global]
pid = /var/run/php-fpm.pid
;error_log = /dev/stderr
syslog.facility = daemon
syslog.ident = php-corefpm
log_buffering = no
log_level = error
emergency_restart_threshold = 1
emergency_restart_interval = 12h
[common_pool]
user = www
group = www
listen = /var/run/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0666
;listen.allowed_clients = 127.0.0.1
catch_workers_output = yes
decorate_workers_output = no
php_flag[display_errors] = off
;php_admin_value[display_errors] = stderr
;php_admin_value[error_reporting] = E_ALL
;php_admin_value[log_errors] = On
;php_admin_value[error_log] = stderr
php_admin_flag[log_errors] = on
php_admin_flag[fastcgi.logging] = off
pm = dynamic
pm.max_children = 50
pm.start_servers = 7
pm.min_spare_servers = 4
pm.max_spare_servers = 10
pm.max_requests = 500
pm.status_path = /fpmstatus
slowlog = /var/log/php/php-fpm.slow.log
request_slowlog_timeout = 10s
ping.path = /ping
This is not working for me.
At the beginning of my journey, I was confused about how nginx actually gets this information and thought it magically happens through STDERR descriptor from php-fpm to nginx, but then I did some digging into the FastCGI protocol, and it looks like backend (php-fpm) actually can send this information using FCGI_STDERR record type.
After the finding, I started to dump traffic between nginx and php-fpm, so I discovered that php-fpm is not sending FCGI_STDERR back to nginx when an error on the PHP side happens.
I checked docs of php-fpm configuration a couple of times and haven't found how to allow/force send this FCGI_STDERR back to nginx explicitly.
At this point, I'm completely lost.
This is probably not the best place to ask this kind of question, but I was wondering if this is somehow related to how php configures/complies from ports.
Will appreciate any help