Hide PHP errors and log them to a file or syslog (php-fpm or mod_php)

For production use, you don’t want to show your PHP errors to end users, but you do want to log them for evaluation later. To do so, change the php.ini file and create the following configs.

display_errors = Off
display_startup_errors = Off
html_errors = Off
log_errors = On
error_log = /var/log/php_errors.log
error_reporting = E_ALL & ~E_DEPRECATED

The configuration above will deny all PHP errors being shown to your visitors but will log them all to the logfile shown above.

If you prefer to log them to syslog, change the error_log variable as shown below.

error_log = syslog

Don’t forget to restart Apache if you’re using mod_php or restart your php-fpm service after making changes to the php.ini configs.