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

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, February 18, 2012

Follow me on Twitter as @mattiasgeniar

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.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.