Where are PHP errors logged to if the error_log directive simply says "error_log"? [duplicate]
Asked Answered
C

4

13

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?

Chirrup answered 25/4, 2014 at 6:48 Comment(1)
The canonical is Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel) (despite the over-specific title).Scanderbeg
S
5

When the value simply says error_log (or error_log = error_log in your php.ini file), that means the errors will be written to a file called error_log in the same directory that the error occurs.

So, if you have a file called index.php in /home/user/public_html/ that throws an error, the error will be written to: /home/user/public_html/error_log.

If you have file called resize.php in /home/user/public_html/admin/images/ that throws an error, then the errors will be written to: /home/user/public_html/admin/images/error_log


Source: Display and log errors for PHP

Subternatural answered 2/1, 2017 at 20:42 Comment(1)
It is probably not wise to keep error_log = error_log, because you don't want random people reading your error_log by visiting your website foobar.com/admin/images/error_log. this is a security concern. (unless you set your server settings to not serve error_log files, however)Iy
T
16

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).

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.

Tera answered 25/4, 2014 at 6:58 Comment(5)
there's no /apache in /var/log. but there is an error_log in /usr/local/apache/logs but it doesn't seem to show any PHP errors. when i run my PHP page I'm getting a blank screen and i want to know the syntax error. display_errors is turned off in php.ini.Chirrup
you should be able to turn on display_errors in your php file itself. Just add ini_set("display_errors", 1); at the beginning.Tera
I believe that ini_set("display_errors", 1); tells PHP to echo error messages to the screen via the output HTML.Iceblink
Another location is /var/log/apache2 (extra "2") (observed on a fairly standard LAMP installation on Ubuntu MATE 20.04 (Focal Fossa))).Scanderbeg
in php.ini check APACHE_LOG_DIRDoane
S
5

When the value simply says error_log (or error_log = error_log in your php.ini file), that means the errors will be written to a file called error_log in the same directory that the error occurs.

So, if you have a file called index.php in /home/user/public_html/ that throws an error, the error will be written to: /home/user/public_html/error_log.

If you have file called resize.php in /home/user/public_html/admin/images/ that throws an error, then the errors will be written to: /home/user/public_html/admin/images/error_log


Source: Display and log errors for PHP

Subternatural answered 2/1, 2017 at 20:42 Comment(1)
It is probably not wise to keep error_log = error_log, because you don't want random people reading your error_log by visiting your website foobar.com/admin/images/error_log. this is a security concern. (unless you set your server settings to not serve error_log files, however)Iy
O
0

On Windows 10, IIS 10.0.18362.1, I set this in file php\php.ini:

error_log = "C:\tmp\php_errors.log"

or

error_log = C:\tmp\php_errors.log

or

error_log = \tmp\php_errors.log

phpinfo() shows:

error_log C:\tmp\php_errors.log or \tmp\php_errors.log

Sometimes directly, but always after iisreset (recycling the application pool).

That is where the file is saved.

Without pad: error_log = php_errors.log it will be written where the error occurs. It has already been mentioned.

Oech answered 5/4, 2020 at 11:3 Comment(1)
What do you mean by "Without pad"? Can you elaborate?Scanderbeg
C
-1

Open your php.ini file.

Check the path against error_log.

Controller answered 25/4, 2014 at 6:53 Comment(4)
This should not have gotten downvoted, because this is proper usage as intended. People should use the tools provided the way they were intended and only spin their own solution up if it is inaccessible or not supplied. There's too many people on this site that assume that just because it didn't solve their specific issue (and all of it's related but unreported issues) that it's automatically wrong. This is not wrong, and if it doesn't work, then your server is set up poorly, which is your real problem.Dendritic
I would add though that logs can also be defined in the apache.conf or vhost.conf as well.Dendritic
I agree with voting this down for the simple reason that it doesn't explain anything clearly.Iceblink
What do you mean "Check the path against error_log." (seems incomprehensible)? Can you elaborate? Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the answer should appear as if it was written today).Scanderbeg

© 2022 - 2024 — McMap. All rights reserved.