How to open the error message displayed in php

PHPz
Release: 2023-04-24 15:33:40
Original
880 people have browsed it

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:

  1. Find the PHP.ini file

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.

  1. Open the PHP.ini file

Open the PHP.ini file with any text editor.

  1. Modify error reporting configuration

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

  1. Save and close the PHP.ini file

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:

  1. Opening error reporting in PHP scripts

Use the following code to open error reporting in PHP scripts:

ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>

  1. Modify .htaccess file

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

  1. In the PHP file Write the error report configuration at the beginning

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template