Search code examples
phpapacheerror-handlinglamp

How to send PHP Notice and Warning to error_log instead of on webpage?


I am not sure why I can't find information about this on the internet but php prints notices and warnings on the web page, which is unacceptable. I know that I can turn it off programmatically on each page, but how do I set a config to just send these errors to my error log? I've been googling like crazy and can't figure it out.

Stuff like this:

<b>Notice</b>: Use of undefined constant LOG_ERROR - assumed 'LOG_ERROR' in  on line <b>12</b><br /> <br /> <b>Warning</b>: syslog() expects parameter 1 to be long, string given in

Solution

  • ini_set('display_errors', '0');
    

    You can include that line at the top of any page, but it's preferred to set it in the php.ini file

    display_errors = Off
    

    Find 'display_errors' in the ini file and set it to off. Then whenever you need a page to display errors for debugging, you can just set:

    ini_set('display_errors', '1');
    

    At the top of the page.