38

Where can I find error log files?

I need to check them for solving an internal server error shown after installing suPHP.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user1010966
  • 473
  • 1
  • 6
  • 13
  • 1
    It depends on your logging settings :) CO – Nemoden Oct 11 '12 at 07:43
  • 1
    my server is centos but it doesnt show anything under var/log/httpd – user1010966 Oct 11 '12 at 07:46
  • Check if [`error_log`](http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log) path is set in php.ini. If not set it will be usually logged in the web server's error log. – air4x Oct 11 '12 at 07:47
  • Look for `error_log` in `php.ini`, if you use `php-fpm`, you might also wanted to check `error_log` in php-fpm conf file – Nemoden Oct 11 '12 at 07:48
  • This is a super FAQ. A candidate for the canonical question: *[Where does PHP store the error log? (php5, apache, fastcgi, cpanel)](https://stackoverflow.com/questions/5127838/)*. The title is somewhat specific, but the answers are certainly not (not all of them). – Peter Mortensen Sep 18 '21 at 19:06

8 Answers8

29

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
16

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RDK
  • 4,540
  • 2
  • 20
  • 29
  • Why should I make sure display_errors is off? Surely this shouldn't affect error logging, does it? – User Sep 05 '14 at 14:47
  • As stated in the answer, `display_errors` determines whether errors are displayed *to the end-user* (e.g. on the rendered webpage), so no, it doesn't affect logging. http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors – cincodenada Apr 27 '16 at 18:13
  • There is no error_log in php.ini for xammpp. Where do I find this? – Adamantus Nov 08 '20 at 16:21
6

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hiasl86
  • 99
  • 2
  • under /var/log there is no any folder or files named apache2 or apache. My server is centos - apache – user1010966 Oct 11 '12 at 07:47
  • under /var/log/httpd ? You can config the log location of apache in the apache.conf file. this should be located somewhere at /etc/httpd/ – hiasl86 Oct 11 '12 at 08:42
6

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bradley Flood
  • 10,233
  • 3
  • 46
  • 43
5

This will definitely help you,

Enable PHP error logging

Or

In php.ini (vim /etc/php.ini or sudo vim /usr/local/etc/php/7.1/php.ini)

display_errors = Off

log_errors = On

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

Make the log file, and writable by user www-data:

sudo touch /var/log/php-errors.log

/var/log/php-errors.log

sudo chown <owner>:www
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pratik Mehta
  • 707
  • 8
  • 27
1

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

/usr/local/apache/log
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AnukuL
  • 595
  • 1
  • 7
  • 21
  • Some [LAMP](https://en.wikipedia.org/wiki/LAMP_%28software_bundle%29) installations on Linux may use `/var/log/apache2/error.log`. – Peter Mortensen Sep 18 '21 at 19:08
1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mopsyd
  • 1,877
  • 3
  • 20
  • 30
1

For Unix CLI users:

Most probably the error_log ini file entry isn't set. To verify:

php -i | grep error_log
// error_log => no value => no value

You can either set it in your php.ini CLI file, or just simply quickly pipe all standard error yourself to a file:

./myprog 2> myerror.log

Then quickly:

tail -f myerror.log
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
NVRM
  • 11,480
  • 1
  • 88
  • 87