Home  >  Article  >  Backend Development  >  How to enable php error reporting function in Nginx

How to enable php error reporting function in Nginx

PHPz
PHPzOriginal
2023-03-24 12:57:271270browse

When using PHP and Nginx as a web server, some problems sometimes occur. One of the common problems is that when there is a problem with PHP, the page will display "500 Internal Server Error" or other error pages. At this time, we need to enable PHP's error reporting function to better locate and solve the problem.

Below we will introduce how to enable PHP’s error reporting function in Nginx.

  1. Modify the php.ini configuration file

First, we need to find the php.ini configuration file. You can find it in the terminal with the following command:

php --ini

This command will find the location of the php.ini configuration file. After getting the location of the php.ini configuration file, we can find the following two configuration items:

display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

The above configuration items determine whether PHP displays error messages and error level settings.

We need to set display_errors to On to enable the display of PHP error messages on the page. At the same time, error_reporting determines which error information needs to be displayed on the page.

Modify the above two configuration items as follows:

display_errors = On
error_reporting = E_ALL
  1. Modify the Nginx configuration file

Now, we need to configure Nginx Add the following code snippet to the configuration file:

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO $fastcgi_script_name;

    fastcgi_param  PHP_VALUE "display_errors=On";
    fastcgi_param  PHP_ADMIN_VALUE "error_reporting=E_ALL";

    include        fastcgi_params;
}

The above code connects the FastCGI module to PHP and sets two parameters for PHP: display_errors and error_reporting, making them global settings.

It should be noted that the above code only modifies the Nginx configuration file and does not reload Nginx.

  1. Reload Nginx

We need to reload Nginx to make the Nginx configuration file take effect.

sudo service nginx reload

At this point, we have successfully enabled PHP’s error reporting function and can see PHP’s error message on the page.

Summary

Turning on PHP's error reporting function is very important for website development and maintenance. It can help us better diagnose and solve PHP error problems. This article introduces how to enable PHP's error reporting function, including the steps of modifying the php.ini configuration file, modifying the Nginx configuration file, and reloading Nginx.

The above is the detailed content of How to enable php error reporting function in Nginx. For more information, please follow other related articles on the PHP Chinese website!

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