PHP: Show error on screen when disabled by php.ini

June 16, 2010

It is quite common to run into situations where PHP errors are suppressed or written to a log file somewhere on a live, non-development server. If you are troubleshooting and need to see the error that can be a pain. Luckily PHP and Apache have provided us with two great workarounds. The first happens through a PHP function call in a script, the second is a .htaccess directive which does require special configuration of Apache, but the majority of servers I have worked with allow this functionality.

Place this code near the top of a PHP file

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

This code goes into the .htaccess file. Just be sure your .htaccess file is in the proper directory relative to the code you are trying to debug

php_value display_errors on

Just be sure you turn error printing back off when you are done.