Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx + FastCGI + PHP (php-fpm) not logging caught errors/warnings

Tags:

php

nginx

fastcgi

FastCGI doesn't want to log PHP errors properly. Well, that's not entirely true: it logs errors fine, with a little fiddling; it just won't log anything else, such as warnings.

The notorious FastCGI -> Nginx log bug isn't an issue, necessarily. Errors and warnings from php-fpm go straight to Nginx--but only if they're uncaught. That is, if set_error_handler successfully intercepts an error, no log entry is appended. This means that I can see parse errors, but that's about it.

php-fpm doesn't log PHP errors by itself (separate from nginx) without a bit of a hack. php-fpm's instance configuration file includes these two lines by default:

php_admin_value[error_log] = /mnt/log/php-fpm/default.log
php_admin_flag[log_errors] = on

I changed the error_log path, obviously. I had to add the following line to get it to actually log anything:

php_admin_value[error_reporting] = E_ALL & ~E_DEPRECATED & ~E_STRICT

Version note: the E_STRICT part is unnecessary, as I'm using PHP 5.3.27, but I plan on upgrading to 5.4 at some point. With this line, it logs errors--and only errors--to /mnt/log/php-fpm/default.log. Now, this sets error_reporting to the same value that I have set in php.ini, so something is obviously wrong here. In addition, it doesn't log caught errors: the behavior is identical to that of the nginx log. I tried using the numeric value (22527) instead, but still no luck.

I don't care in which log file the entries end up (nginx versus php-fpm), but I do need caught errors to be logged somewhere. I could resort to injecting my own error and exception handlers, but that's a bit hackish, so I'd rather avoid that.

like image 730
Zenexer Avatar asked Aug 10 '13 02:08

Zenexer


People also ask

Where is PHP-FPM error log?

A complete debug log for PHP-FPM errors can be found in the /opt/bitnami/php/var/log directory.

Does nginx require PHP-FPM?

Nginx is the DevOps community's most beloved http web server. And developers love the PHP programming language because it enables them to quickly build and deploy interactive websites. As such, it's no wonder that so many sys admins need to configure Nginx, PHP and PHP-FPM on both Linux and Windows servers.

How can I tell if PHP-FPM is running?

First open the php-fpm configuration file and enable the status page as shown. Inside this file, find and uncomment the variable pm. status_path = /status as shown in the screenshot. Save the changes and exit the file.


1 Answers

I use this directive in the pool configuration file for PHP-FPM:

catch_workers_output = yes

like image 168
parhamr Avatar answered Nov 14 '22 23:11

parhamr