Enable showing errors in PHP5

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, August 24, 2008

Follow me on Twitter as @mattiasgeniar

In case your PHP scripts aren’t showing you the necessary errors, you can add the following 2 lines to your script – these will enable errors in the current page (and any others page you include afterwards), without affecting it server-wide.

error_reporting(E_ALL);
ini_set("display_errors", 1);

The setting error_reporting determines what kind of errors you want displayed. Only warnings, errors or fatal errors? A combination of those? More details can be found on the PHP website on error_reporting.

On top of that setting, there’s the “display_errors"-parameter. If that’s turned to “0”, no errors will be displayed at all, no matter what you’re setting in error_reporting. Turn this to 1 using the ini_set command, and TADAAAA; your errors are showing.

Happy debugging!



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.