Main Content

Error logging to file not browser in PHP

Archive - Originally posted on "The Horse's Mouth" - 2007-10-11 23:43:13 - Graham Ellis

When you first install PHP on your web server, any errors and warnings in you code are flagged up in the browser window. And that's ideal for development purposes - any problems are quickly indicated to you, with pointers to where the issue lies.

But when you go live, there's a different story, Of course, there shouldn't be any problems remaining ... but ... if there are, then you'll not want your user to be alerted to the detail, including the line of code in which it occurred.

You can change the error behaviour of PHP through configuration switches in your php.ini file .... turning the display of errors off, and turning logging to file on. These two lines:

display_errors = On
log_errors = Off


being replaced by these three:

display_errors = Off
log_errors = On
error_log = /home/octoweb/oops.txt