global and permanent: activate logging to file and html output:

vim /etc/php5/cgi/php.ini # open up your default configuration file, how to find the default config check here

; check that these options are On
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = On
log_errors = On
html_errors = On
; this is the file the errors will be written to
error_log = /var/www/php_errors.log
; if you can not find php_errors.log another default filename for logs is script_errors.log

after changes @ php.ini – don’t forget to restart your webserver!

/etc/init.d/lighttpd restart

per-file and temporary error logging:

Set error logging with ini_set()

Although this is not ideal you can use the ini_set() function to set the above configuration options to log errors. It is not an ideal solution because it will not log any errors if the script has parse errors and cannot be run at all. For example:

ini_set("log_errors", 1);
ini_set("error_log", "/path/to/php-error.log");

Set error logging in .htaccess and virtualhost directives

This is a better option because it will log the errors even if there’s a parsing error in your script.

php_value log_errors 1
php_value error_log /path/to/php-error.log

Example error log data

A couple of example lines from an error log are as follows:

[13-May-2009 21:54:04] PHP Notice:  Undefined variable: x in /common/websites/test/error-log.php on line 6
[13-May-2009 21:54:09] PHP Parse error:  syntax error, unexpected '}' in /common/websites/test/error-log.php on line 5

if you want see errors as they happen in „real-time“ you can use

less /var/www/php_errors.log

and thenn hit: Shift+F -> Follow file changes

there is also a: Webserver Error log

lighttpd error log:

less /var/log/lighttpd/error.log