Home  >  Article  >  Backend Development  >  Turn on PHP debugging_PHP tutorial

Turn on PHP debugging_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:45:22888browse

1. Configuration files involved:
/etc/php5/apache2/php.ini
2. Specific line:
display_errors =
error_reporting =
3. Remember to restart the service

Error reporting for PHP
There are many configuration settings in the php.ini file. You should have set up your php.ini file and placed it in the appropriate directory, as documented in the instructions for installing PHP and Apache 2 on Linux (see Resources). There are two configuration variables that you should be aware of when debugging PHP applications. Here are the two variables and their default values:
display_errors = Off
error_reporting = E_ALL

The current default values ​​of these two variables can be found by searching for them in the php.ini file. The purpose of the display_errors variable is obvious - it tells PHP whether to display errors. The default value is Off. However, to make the development process easier, set this value to On:
display_errors = On

The default value of the error_reporting variable is E_ALL. This setting will show everything from bad coding practices to harmless tips to errors. E_ALL is a bit too granular for development purposes, as it also displays hints on the screen for small things (such as variables not being initialized), which messes up the browser's output. I only want to see errors and bad coding practices, but not harmless tips. So, please replace the default value of error_reporting with the following value:
error_reporting = E_ALL & ~E_NOTICE

Restart Apache and you're all set.

Error reporting on Apache server
Depending on what Apache is doing, turning on error reporting in PHP may not work since there may be multiple versions of PHP on the machine. Sometimes it's difficult to tell which PHP version Apache is using because Apache can only look at one php.ini file. Not knowing which php.ini file Apache is using to configure itself is a security issue. However, there is a way to configure PHP variables in Apache so that the correct error level is set.
Also, it's a good idea to know how to set these configuration variables on the server side to override or preempt the php.ini file, thus providing a higher level of security.
When configuring Apache, you should have already touched the basic configuration in the http.conf file in /conf/httpd.conf.
To do what you have already done in the php.ini file, add the following lines to httpd.conf, overwriting any php.ini files:
php_flag display_errors on
php_value error_reporting 2039

This overrides the flag already set in the php.ini file for display_errors, as well as the value of error_reporting. The value 2039 represents E_ALL & ~E_NOTICE. If you prefer to use E_ALL, set the value to 2047. Again, you still need to restart Apache.
Next, you want to test error reporting on the server.
Test bug report
If error reporting is enabled, a lot of time will be saved. Errors in PHP point to errors in your code.

--EOF--
Author “Growth Footprints”

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478660.htmlTechArticle1. Involved configuration file: /etc/php5/apache2/php.ini 2. Specific line: display_errors = error_reporting = 3. Remember to restart the service PHP error reporting There are many configurations in the php.ini file...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn