Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find error log files for PHP?

People also ask

How do I find the error log file?

The name and the location of the log is set by the ErrorLog command and the default apache access log file locations are: RHEL / Red Hat / CentOS / Fedora Linux Apache access log file location – /var/log/httpd/error_log. Debian / Ubuntu Linux Apache access log file location – /var/log/apache2/error. log.

Where does PHP log errors by default?

By default, whenever an error or exception is thrown, PHP sends the error message directly to the user via STDOUT. In a command-line environment, this means that errors are rendered in the terminal. In a web environment, errors and exceptions get displayed directly in the browser.

Is there a PHP log?

Enabling the PHP Error LogLog messages can be generated manually by calling error_log() or automatically when notices, warnings, or errors come up during execution. By default, the error log in PHP is disabled. You can enable the error log in one of two ways: by editing php. ini or by using ini_set.


You can use lsof to find open logfiles on your system. lsof just gives you a list of all open files.

Use grep for "log" ... use grep again for "php" (if the filename contains the strings "log" and "php" like in "php_error_log" and you are the root user you will find the files without knowing the configuration).

lsof | grep log

... snip
gmain     12148 12274       user   13r      REG              252,1    32768     661814 /home/user/.local/share/gvfs-metadata/home-11ab0393.log
gmain     12148 12274       user   21r      REG              252,1    32768     662622 /home/user/.local/share/gvfs-metadata/root-56222fe2.log
gvfs-udis 12246             user  mem       REG              252,1    55384     790567 /lib/x86_64-linux-gnu/libsystemd-login.so.0.7.1
==> apache 12333             user  mem       REG              252,1    55384     790367 /var/log/http/php_error_log**
        ... snip
lsof | grep log | grep php

**apache 12333             user  mem       REG              252,1    55384     790367 /var/log/http/php_error_log**
... snip

Also see this article on finding open logfiles: Find open logfiles on a Linux system


It works for me. How can we log all PHP errors to a log file?

Just add the following line to file /etc/php.ini to log errors to specified file – file /var/log/php-scripts.log

vi /etc/php.ini

Modify the error_log directive:

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

Make sure display_errors is set to Off (no errors to end users):

display_errors = Off

Save and close the file. Restart the web server:

/etc/init.d/httpd restart

How do I log errors to syslog or Windows Server Event Log?

Modify error_log as follows:

error_log = syslog

How can we see logs?

Login using ssh or download a log file /var/log/php-scripts.log using SFTP:

sudo tail -f /var/log/php-scripts.log

On CentOS with cPanel installed, my logs were in:

/usr/local/apache/logs/error_log

To watch: tail -f /usr/local/apache/logs/error_log


It depends on what OS you are using and which web server.

On Linux and Apache, you can find the Apache error_log in folder /var/log/apache2/.


I am using CentOS 6.6 with Apache and for me error log files are in:

/usr/local/apache/log

This is a preferable answer in most use cases, because it allows you to decouple execution of the software from direct knowledge of the server platform, which keeps your code much more portable. If you are doing a lot of cron or CGI, this may not help directly, but it can be set into a configuration at web runtime that the cron and CGI scripts pull from to keep the log location consistent in that case.


You can get the current log file assigned natively to PHP on any platform at runtime by using:

ini_get('error_log');

This returns the value distributed directly to the PHP binary by the web server, which is what you want in 90% of use cases (with the glaring exception being CGI). CGI will often log to this same location as the HTTP web server client, but not always.

You will also want to check that it is writeable before committing anything to it to avoid errors. The configuration file that defines its location (typically either file apache.conf globally or vhosts.conf on a per-domain basis), but the configuration does not ensure that file permissions allow write access at runtime.