How do I log errors and warnings into a file?

Gorep picture Gorep · Aug 20, 2010 · Viewed 359.4k times · Source

How do I turn on all error and warnings and log them to a file, but to set up all of that within the script (not changing anything in php.ini)?

I want to define a file name and so that all errors and warnings get logged into it.

Answer

Aman picture Aman · Aug 20, 2010

Use the following code:

ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_log( "Hello, errors!" );

Then watch the file:

tail -f /tmp/php-error.log

Or update php.ini as described in this blog entry from 2008.