Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains how to configure the log of PHP errors when using PHP-FPM in Nginx. Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to configure logging PHP errors when using PHP-FPM in Nginx.

Nginx is different from apache in that you can specify the error log of php directly in apache, so that the error information in the execution of php is directly entered into the error log of php, which is convenient for query.

In nginx, things become like this: nginx only keeps access logs for page visits. There will be no error log information for php. 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 errorlog of php can not be seen in the errors log of php-fpm.

The reason is that php-fpm 's configuration file php-fpm.conf turns off the error output of the worker process by default and redirects them directly to / dev/null, so we can't see the error log of php in nginx's errorlog and php-fpm 's errorlog.

So we need to make the following settings to see how php-fpm does not log php errors under nginx:

1. Modify the configuration in php-fpm.conf. If not, add:

The copy 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

two。 Modify the configuration in php.ini. If not, add:

The copy 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:

The copy 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

Then in the first step, carefully write the configuration to the corresponding group, otherwise the above will appear:

The copy code is as follows:

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

Finally, take a look at the effect:

At this point, I believe you have a deeper understanding of "how to configure recording PHP error logs when using PHP-FPM in Nginx". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report