Find Out the Error_Log's Path

Find out the error_log's path

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');
?>

Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel)

PHP stores error logs in /var/log/apache2 if PHP is an apache2 module.
Shared hosts are often storing log files in your root directory /log subfolder.
But...if you have access to a php.ini file you can do this:

error_log = /var/log/php-scripts.log

According to rinogo's comment: If you're using cPanel, the master log file you're probably looking for is stored (by default) at

/usr/local/apache/logs/error_log

If all else fails you can check the location of the log file using

<?php phpinfo(); ?>

How to set different path for php error_log file?

The manual says it's PHP_INI_ALL, so you can set it at runtime.

  • Notably that'll have no effect to any messages generated prior calling ini_set.

  • Better option would be to use one of the SAPI-dependant configuration schemes (.user.ini or .htaccess)

Also take in mind that the destined log path needs to be writeable by the Apache or FPM process, of course.

Specify a relative path to 'php_value error_log'

You can set it to ./path/error.log.

Get the PHP error log from PHP on remote hosting

On a badly secured server, yes. But on most servers there are two users: apache and [ you ]. You don't have access to the server logs, since they are owned by the apache user (or whichever server you're using).

However, you could probably try it:

echo file_get_contents('/var/log/httpd/error_log');

Note: that's the default location on a RedHat-based apache server. It may be different

Update To reflect the updated question
No, you cannot view the error log with error_log - it is a one-way process that gets handled by the webserver. It only writes the log, but you cannot read it.

You can probably display the errors with this:

ini_set('display_errors', 'On');
error_reporting(E_ALL);

You could even use set_error_handler to handle all warnings and notices (for example, to mail them). But that's pretty much all you can do.

php not logging errors log_errors=on, error_log path exists

From above comments. When using Apache2, each VirtualHost can have it's own log files.

So the /etc/apache2/ directory would have a sites-available directory along these lines:

├── sites-available
│   ├── 000-default.conf
│   ├── default-ssl.conf
│   ├── default-tls.conf
│   ├── www.domain.com.conf
│   └── www.domain.com-le-ssl.conf

And the www. files might look like the following example.

To set up specific php log file, separate from Apache logs, follow this answer:

<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/domains/example.com/html
ErrorLog /var/www/domains/example.com/apache.error.log
CustomLog /var/www/domains/example.com/apache.access.log common
php_flag log_errors on
php_flag display_errors on
php_value error_reporting 2147483647
php_value error_log /var/www/domains/example.com/php.error.log
</VirtualHost>

error_log in the same directory as included files?

Based on hakre's suggestions above, I've created this script, to be included at the top of any php script:

(also here is a gist I made of this file if you wish to fork/download it: view on github )

<?
function custom_error_debug($errno, $errstr, $errfile, $errline, $errvars) {
$message = "";
$message .= "[ " . date('Y-m-d h-i-s') . " ] Error: [$errno] $errstr on line $errline of $errfile ";

//Dump all info to browser!
//WARNING: Leave this commented except for extreme cases where you need to see all variables in use!
//Using this will cause excessive processing time, and RAM. Use only as needed!
/*if (!empty($errvars)) {
echo $message . PHP_EOL . "Variables in use: <pre>";print_r($errvars); echo "</pre>";
//WARNING: not ending execution here may cause the browser to overload on larger frameworks, comment out at your own risk!
die();
}*/

//get the directory of the offending file, put a log in that path, and separate them by end of line, append to file
file_put_contents ( dirname($errfile) . "/php_errors.log", $message . PHP_EOL, FILE_APPEND );

//Dump all variables to file as well, (MAY CAUSE LARGE FILES, read above)
//file_put_contents ( dirname($errfile) . "/php_errors.log", $errvars . PHP_EOL, FILE_APPEND );

//Optionally end script execution
//die();
}
set_error_handler('custom_error_debug');
?>


Related Topics



Leave a reply



Submit