Php – How to make the Apache/PHP setup on the VPS show PHP errors and warnings

apache-2.2PHPphp.ini

I've got a VPS using Suse Linux 10.3.

Apache 2 / PHP 5.2.6 was set up automatically.

When I look at this valid PHP file in a browser, it displays correctly:

<?php
echo 'this is test';
?>

However, when I look at this invalid PHP file, I expect it to show me an error, but it shows absolutely nothing, blank page, no source:

<?php
nnn 'this is test';
?>

Via phpinfo() I found that the "loaded php.ini configuration file" is at /etc/php5/apache2/php.ini and in that file I found this uncommented line:

error_reporting  =  E_ALL

which tells me that it should be showing all errors and warnings.

What else do I have to do so that PHP shows errors?

Best Answer

Normally, web applications will log errors to the Apache error log. This is the file specified in the relevant ErrorLog setting for your server or virtual host section. PHP applications will send logs there, but they aren't entirely the most accessible or useful logs; your logging can get lost between other errors. PHP can be configured to log to a separate log file, but this is not very different from logging to the Apache error log. You can configure Apache to log errors to the browser using

display_errors = On

in your php.ini. With this, log lines will appear in your browser. You really should not use this option on a production system. If you need to mix production and development applications on the same system, you can use:

ini_set("display_errors","On");

at the top of your development php files.

The error_reporting option changes what PHP reports.

You can do better though. XDebug is a PHP extension which adds some very useful PHP development features, like stack traces, profiling and code coverage.

Related Topic