1

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?

1 Answer 1

2

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.

3
  • Note: Do keep in mind to give necessary write permission to your log file. I'll recommend giving 0777. Oct 24, 2015 at 17:23
  • It helps, but running both PHP with suPHP handler and CloudLinux, needs a little workaround to register globals in PHP configuration, to make use of php_flag and php_value directives.
    – Alan Kis
    Oct 24, 2015 at 17:28
  • I get this error httpsdocs/.htaccess: Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration
    – theking2
    Oct 26, 2022 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.