Home > Article > Backend Development > What should I do if the php error log is output?
Solution to output php error log: 1. Modify the configuration in [php-fpm.conf], if not, add it; 2. Modify the configuration in [php.ini], if not, add it; 3. Restart [ php-fpm].
Solution to output php error log:
1. Modify php-fpm.conf Configuration, if not, add
catch_workers_output = yes error_log = log/error_log
2. Modify the configuration in php.ini, if not, add
log_errors = On error_log = "/usr/local/lnmp/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/error_log
"
Please note:
1 The php_admin_value[error_log] parameter in 1.php-fpm.conf will override the error_log parameter in php.ini
So make sure the final error_log
file you see in phpinfo()
has writable permissions and does not have the php_admin_value[error_log]
parameter set, otherwise there will be an error The log will be output to the error log of php-fpm
.
2. The php.ini location cannot be found, use php's phpinfo()
to view the results
3. How to modify the PHP error log not to be output to the page or screen
Modifyphp.ini
display_errors = off
/ /Do not display error information (do not output it to the page or screen)log_errors = on
//Record error information (save it to the log file)error_reporting = E_ALL
//Capture all error messages error_log =
//Set the log file name
Modify the above configuration in the program
ini_set("display_errors",0) ini_set("error_reporting",E_ALL); //这个值好像是个PHP的常量 ini_set("error_log","<日志文件名>") ini_set("log_errors",1);
4. How Output the error log of php to the error log of nginx
In PHP 5.3.8 and previous versions, if an error occurs during user access when PHP is run through FastCGI, it will first be written to the errorlog of PHP Medium;
If PHP's errorlog cannot be written, the error content will be returned to the FastCGI interface, and then nginx will record it in the nginx errorlog after receiving the error return from FastCGI;
In PHP 5.3.9 and later In the version, PHP will only try to write to PHP's errorlog after an error occurs. If it fails, it will not return to FastCGI, and the error log will be output to the error log of php-fpm.
So if you want to output the php error log to the nginx error log, you need to use a version before php5.3.8, and the error_log of php in the configuration file is not writable for the php worker process
Related learning recommendations : PHP programming from entry to proficiency
The above is the detailed content of What should I do if the php error log is output?. For more information, please follow other related articles on the PHP Chinese website!