简体   繁体   中英

How to log an PHP error_log error message to Apache server error_log?

I am running a VPS server with cPanel on it. I have set up all Apache server errors to log to /usr/local/apache/logs/error_log.

Is possible to log error message to Apache error log, instead of user PHP related error_log in /home/user/public_html/error_log.log

I have this snippet for testing, but everything I get is my custom error_log message logged in error_log file inside my public_html/ instead in Apache error_log.

<?php

/**
 *
 * Logs a message to Apache server error_log at /usr/local/apache/logs/error_log
 * 
 * 
 */

error_log("Just a ordinary Apache error_log for testing", 0, "/usr/local/apache/logs/error_log.log") // logs to user error_log in public_html/

Is this even possible?

Use apache .htaccess file in your web root for logging all the errors and warnings.

Inside .htaccess file:

php_flag  log_errors on
php_value error_log  /usr/local/apache/logs/error_log.log

In this way you don't have to write codes for every error occurrence. Appache will log all the errors and warnings automatically to your specified error log file.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM