In PHP, when the program encounters an error, error information is usually automatically recorded, but by default this information will not be displayed on the web page. This is very inconvenient for debugging PHP programs. Therefore, for better debugging, PHP display error messages needs to be turned on.
Open PHP error report
The PHP.ini file is the configuration file of PHP, in which many configurations can be made. By modifying the error reporting configuration in the PHP.ini file, you can turn on PHP's error display function. Here are the specific steps:
Before you begin, you need to know the location of the PHP.ini file. The PHP.ini file is generally located in the root directory of the PHP installation directory. If you don’t know the location of the PHP installation directory, you can enter php -i on the command line to view relevant information.
Open the PHP.ini file with any text editor.
Search for the display_errors keyword in the PHP.ini file. If the configuration item is commented, you need to uncomment it; if it is not defined, you need to add the following code:
display_errors = On
If you need to display the error and warning information recorded by PHP at the same time, you can Set the following code:
error_reporting=E_ALL
After saving the modifications, you need to restart the web server or PHP- FPM can take effect.
Other ways to open PHP error reporting
The above method to modify the PHP.ini file is only valid for the current PHP version. If you need to use the same configuration between multiple PHP versions, it will be troublesome. So, here are other ways to open PHP error reporting:
Use the following code to open error reporting in PHP scripts:
ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>
Add the following code in the .htaccess file to turn on PHP error reporting:
php_flag display_errors on
php_value error_reporting E_ALL
Write the following code at the beginning of the PHP file to open the PHP error report:
error_reporting(E_ALL);
ini_set ('display_errors', 1);
?>
Summary
When debugging PHP programs, it is very important to turn on PHP error reporting. Sometimes we just need to simply turn on error reporting in a PHP script, and other times we need to modify the PHP.ini file. This can greatly improve debugging efficiency and speed up program development progress.
The above is the detailed content of How to open the error message displayed in php. For more information, please follow other related articles on the PHP Chinese website!