Most servers are set to suppress PHP errors which can leave you guessing why something isn't working and make troubleshooting code almost impossible. This is especially frustrating when you install a 3rd party module with errors. Luckily forcing PHP to display errors is very easy.
The most basic way to accomplish this is to just add the following 2 lines to the top of your PHP code.
Copy this code…
error_reporting(E_ALL);
ini_set( 'display_errors','1');
You can just individually place this code in each page your debugging OR if you're using a system such as drupal or wordpress you can just add this to the top of your settings file as it is included in every page of the site so it will make all the pages show errors. This is very useful for development just remember to remove it before taking the site live
Drupal: /sites/default/settings.php
WordPress: /wp-config.php
Alternative for live sites – making PHP save errors to a log file
Obviously this is a reason why the PHP errors don't show. So before taking a site live you should disable them again. However, If errors do happen you might want a simple way to be able to see whats going on without letting the whole world see that your page is throwing errors.
Again the solution is simple. Just put the following code in you .htaccess file. Just be sure to update the path listed for your error file to reflect the actual location you want the error file to store. Also make sure that the server has write permissions to the file.
php_flag log_errors on php_value error_log /home/path/public_html/domain/PHP_errors.log
Tony
July 8, 2011 at 4:19 am
In the above code you have put an accent instead of an apostrophe after the ’1′, just in case anybody is wondering why copying and pasting the code produces errors.
Tony
July 8, 2011 at 4:21 am
Interesting. My trailing apostrophe was automatically replaced with an accent exactly the same as with yours.
Lenny
September 21, 2011 at 1:08 pm
This was a weird glitch with the code highlighter plugin I’m using… I can’t seem to get it to stop changing my final ‘ in to a “fancy quote” … Why a code highlighter would add in “fancy quotes” I have no idea… Anyways, I took it out of the code highlighter and now you can copy the code to show error messages in php as is without an issue.