Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

error-log

I ran phpinfo() and the error_log directive simply says error_log. What file is that referring to? i.e. what would the full path to the error_log be?

like image 869
Ryan Avatar asked Apr 25 '14 06:04

Ryan


People also ask

Where do I find PHP error logs?

The location of the error log file itself can be set manually in the php. ini file. On a Windows server, in IIS, it may be something like "'error_log = C:\log_files\php_errors. log'" in Linux it may be a value of "'/var/log/php_errors.

Where are PHP error logs Apache?

If you have build Apache and PHP from source, then the error logs by default is generated at your ${Apache install dir}/logs/error_log , i.e., generally /usr/local/apache2/logs/error_log .

Where is PHP FPM error log?

In PHP 8 Linux Azure App Service, the original php-fpm config file is stored in /usr/local/etc/php-fpm. d/www. conf. By default, php-fpm access log is disabled in the config.

What is the error log in PHP?

This is where the error log comes into play. By default, PHP doesn't log any errors, which means that this value must be explicitly set. To do so, open up the same PHP configuration file referenced above in your favorite editor and find the error_log directive.

How to list all error logs in a specific directory?

You should use absolute path when setting error_log variable in your php.ini file, otherwise, error logs will be stored according to your relative path. Other solution would be writing simple script which would list all error logs files from directory tree. Show activity on this post. This is helpful. Show activity on this post.

Where can I find the PHP logs?

If it is, the log file location will depend on the operating system and the mode PHP is running. If PHP is running as an Apache module, on Linux the log often is in /var/log/apache2/error.log. Another likely spot is in a logs directory in your account home directory, ~/logs/error.log.

How to log to an error log file in Linux?

To log to an error log file specified with the error_log configuration option set this to 1. The error_log configuration option is a string and is the filename of where to log errors. It can contain either a relative path or an absolute path as part of the filename.


1 Answers

Quote from the documentation:

error_log string

Name of the file where script errors should be logged. The file should be writable by the web server's user. If the special value syslog is used, the errors are sent to the system logger instead. On Unix, this means syslog(3) and on Windows NT it means the event log. The system logger is not supported on Windows 95. See also: syslog(). If this directive is not set, errors are sent to the SAPI error logger. For example, it is an error log in Apache or stderr in CLI.

So, when the value is not set (which is the default) it will be sent to the parent error logger, which is apache (if run via it) or stderr if you run the script on the command line.

If you use the script via apache you will have to look at the apache error log, usually in /var/log/apache or /var/log/httpd, depending on your distribution. You can check the apache configuration file for the exact location.

Edit:

I just noticed I misread your question, I guess you mean error_log has the actual value error_log?

I just did some testing. When I set error_log to a value like php_errors.log PHP still writes the error messages to the apache error log. It behaves as if the value was empty. When I set the value to a full path (e.g. /tmp/php_errors.log) then it writes the errors to the specified file.

So I guess in your case it writes the errors to the apache error log file.

Of course you can set your own log file be adding

ini_set("error_log", "/tmp/php_errors.log");

to your PHP files where you need it (if it hasn't been disabled by an administrator).

like image 98
Gerald Schneider Avatar answered Oct 16 '22 10:10

Gerald Schneider