Introduction to PHP for Os X by Example

When Things Go Wrong?

There are several ways you can get feed back from PHP when things go wrong. By far the most useful, is to have errors displayed in the browser window. Another way is to have the errors written to the Apache servers httpd error_log.

By default (in Marc Liyanage’s package) the first method is switched off and the second is switched on. The reason for this is that, if you are going to run PHP as a production service you realy don’t want the errors going to the browser window.

The easiest way to take advantage of the errors written to the httpd error_log is to tail the log.

We can find the location of the error log using the command, httpd –V. To see the last half dozen or so lines of the httpd error_log use tail.

e.g.

% tail /var/log/httpd/error_log

As the first method – have the errors displayed in the browser window – is the most useful, here is how to switch it on.

Find the location of your php.ini file (usually /usr/local/php5/lib/php.ini). We can find the location of this file in the output from the phpinfo() function (see: Hello PHP!).

Open the php.ini file in a text editor and change display_errors = Off to display_errors = On. Make sure you change the actual configuration line not the commented line.

N.B. Don’t forget to change it back when your project goes from development to production phase.

The kind of errors that get reported to you are controlled by the error_reporting setting in the php.ini file. It is beyond the scope of this workshop to go into what all the settings for this are but the default is generally a safe bet.

You can find out more about the error_reporting setting at the official PHP web site.