How to display errors in PHP

Line 1: Line 1:
====Displaying Error Messages in PHP====
====Displaying Error Messages in PHP====
-
This assumes you have already installed PHP on your computer. By default, most PHP installations will not display error messages in the browser. This is a security feature. However, during development it's a good idea to display error messages.  To set up your environment to '''display errors''':
+
This assumes you have already installed PHP on your computer. By default, most PHP installations will not display error messages in the browser. This is a security feature. However, during development it's a good idea to display error messages
 +
 
 +
PHP5 is supposed to allow you to override the system-wide configuration settings by including a '''php.ini''' file in your current working directory (the directory that contains you script).  However, there appears to be a bug in PHP 5.1 as described in [http://bugs.php.net/bug.php?id=38714 this bug report].  Apparently, PHP 5.1 just ignores (or overrides) the settings in the local php.iniTo get around this problem, you can either modify the system-wide php.ini file, as described below, or you can use the work around described here.
 +
 
 +
====Work Around Procedure====
 +
 
 +
====Set display_errors=On in the System php.ini====
 +
To set up your environment to '''display errors''':
1. Find the PHP configuration file '''php.ini''' on your system. (On the Mac it is: /usr/local/php5/lib/php.ini)
1. Find the PHP configuration file '''php.ini''' on your system. (On the Mac it is: /usr/local/php5/lib/php.ini)

Revision as of 16:31, 5 February 2007

Displaying Error Messages in PHP

This assumes you have already installed PHP on your computer. By default, most PHP installations will not display error messages in the browser. This is a security feature. However, during development it's a good idea to display error messages.

PHP5 is supposed to allow you to override the system-wide configuration settings by including a php.ini file in your current working directory (the directory that contains you script). However, there appears to be a bug in PHP 5.1 as described in this bug report. Apparently, PHP 5.1 just ignores (or overrides) the settings in the local php.ini. To get around this problem, you can either modify the system-wide php.ini file, as described below, or you can use the work around described here.

Work Around Procedure

Set display_errors=On in the System php.ini

To set up your environment to display errors:

1. Find the PHP configuration file php.ini on your system. (On the Mac it is: /usr/local/php5/lib/php.ini)

On Macintosh or Linux: $locate php.ini

2. Edit php.ini and search for the these lines (which will not be consecutive):

error_reporting = E_ALL
display_errors = Off

and change them to:

error_reporting = E_ALL & ~E_NOTICE | E_STRICT
display_errors = On

3. Restart Apache:

$ sudo apachectl restart