Home  >  Article  >  Operation and Maintenance  >  How to configure PHP error logs when using PHP-FPM in Nginx

How to configure PHP error logs when using PHP-FPM in Nginx

PHPz
PHPzforward
2023-05-15 08:58:121359browse

nginx is different from apache. In apache, you can directly specify the error log of php, so that the error information during php execution is directly entered into the error log of php, which can be easily queried.

In nginx, things become like this: nginx only records access logs for page visits. There will be no php error log information. nginx sends the request for php to the php-fpm fastcgi process for processing. The default php-fpm will only output the error message of php-fpm, and the error log of php cannot be seen in the errors log of php-fpm.

The reason is that the php-fpm configuration file php-fpm.conf defaults to turning off the error output of the worker process and redirecting them directly to /dev/null, so we use nginx’s error log and php- The error log of fpm cannot see the error log of php.

So we need to make the following settings to see how php-fpm does not record php error logs under nginx:

1, modify the configuration in php-fpm.conf , if not please add:

Copy the code The code is as follows:

[global]
; note: the default prefix is ​​/usr/local/php/var
error_log = log/php_error_log
[www]
catch_workers_output = yes

2. Modify the configuration in php.ini, if not, add:

Copy code The code is as follows:

log_errors = on
error_log = "/usr/local/php/var/log/error_log"
error_reporting=e_all&~e_notice

3. Restart php-fpm

When php executes an error, you can see the error log in "/usr/local/lnmp/php/var/log/php_error_log"

If it appears:

Copy code The code is as follows:

[root@localhost etc]# service php-fpm restart
gracefully shutting down php -fpm . done
starting php-fpm [17-apr-2014 18:40:52] error: [/usr/local/php/etc/php-fpm.conf:5] unknown entry 'catch_workers_
[17-apr-2014 18:40:52] error: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[17-apr-2014 18:40:52] error: fpm initialization failed
failed

In the first step, please carefully write the configuration into the corresponding group, otherwise the above message will appear:

Copy code The code is as follows:

error: [/usr/local/php/etc/php-fpm.conf:5] unknown entry 'catch_workers_output'

Finally look at the effect:
How to configure PHP error logs when using PHP-FPM in Nginx

How to configure PHP error logs when using PHP-FPM in Nginx

The above is the detailed content of How to configure PHP error logs when using PHP-FPM in Nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete