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

Alan Kis

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?

TipuZaynSultan

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Apache / PHP error_log location in Docker?

How to send PHP Notice and Warning to error_log instead of on webpage?

How to set different path for php error_log file?

Clear error_log file with PHP

log_errors and error_log in php for php.ini

Where are PHP errors logged to if the error_log directive simply says "error_log"?

PHP error_log output format differs for custom log

Laravel logs to error_log?

error_log message is truncated when using print_r

Error_log: PHP Warning: A non-numeric value encountered

PHP different result of error_log and echo in different contexts

Can not set error_log option in PHP with ini_set

\n not putting text on a new line in php error_log function

How can I get phpunit to not swallow error_log output?

error_log per Virtual Host?

error_log per Virtual Host?

Setting error_log location not taken into account

error_log passing parameter to sender

Edit prepended date format in error_log

error_log in the same directory as included files?

Python mod_wsgi write to custom log file instead of apache error_log

Nginx : Error_log and Access_log max size

Huge error_log filled with zeros at Joomla site in public_html directory causing server hang

I got message for error_log file "The stream or file ".../laravel.log" could not be opened: failed to open stream: Permission denied"

grep to search error_log and email only when results found?

Why is error_log not being called during my cron?

Prevent error_log() messages to be printed to the terminal during tests

Where do the logs go with error_log function?

Errors for virtual host are not written to specified ErrorLog, but to default error_log