How to open the error message displayed in php
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:
- 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.
- Open the PHP.ini file
Open the PHP.ini file with any text editor.
- 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
- 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:
- 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);
?>
- 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
- 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
