Find out the error_log's path

I have this domain.com pointed to /home/username/public_html/domain.com.

I added these lines to the .htaccess file:

ErrorDocument 500 /oohps.php
ErrorDocument 404 /where.php

So I can show some styled template.

The problem is that when trying to access a nonexisting page, I get an additional internal server error, so these files are not opened.

I wanted to check for the logs, but I cannot find the error log in that path (/home/username/public_html/domain.com).

I found one in /var/log/httpd, but I don't think it’s the right folder, because there are many errors not involved with this page and I didn't see any involved.

Is there a PHP function that would output the errors log file path?


Solution 1:

An internal server error has often something to do with Apache and /var/log/httpd/ is the error log file of Apache, so I think you are in the right file.


The error path is set in php.ini. To get the path use ini_get():

<?php
  $errorPath = ini_get('error_log');
?>

Solution 2:

To only get the path where PHP stores its logs, use:

pathinfo(ini_get('error_log'),PATHINFO_DIRNAME);

Which should return something like this (on localhost):

/Applications/MAMP/logs

Solution 3:

Check for the error_log setting in file php.ini (or in the output of function phpinfo()).

Solution 4:

As I stumbled upon this problem and ini_get() didn’t help, the following might be a solution for someone else too.

In case error_log is not set in file php.ini or the like, the error is sent to the SAPI error logger. This, in case of e.g. Apache 2, is the error log defined in the Apache vhost configuration. A way to get the Apache log directory would be to check the symlink value of the standard error file descriptor.

An example which works on Linux would be:

$logdir = pathinfo(realpath("/proc/".getmypid()."/fd/2"), PATHINFO_DIRNAME);

This example reads the path of the symlinked file of /proc/[PID]/fd/2 which is the standard error file descriptor.

Solution 5:

I am not aware of such a function, but maybe phpinfo() will have some information about that.

Log paths are defined inside an Apache site's configuration file. If you want a custom path to it, if not by default, all the logs are loaded into /var/log/apache2/*.log, so PHP has nothing to do with it.