In daily website development, we often use Nginx as the web server and PHP as the back-end language. However, sometimes we find that even if there is an error in PHP, Nginx will not prompt any information, which makes it very difficult for us to debug the program. This article will introduce some solutions to enable Nginx to prompt PHP error messages.
1. Understanding error reporting and collection methods
In the process of deploying the server, we habitually turn off the error output of PHP. This is because of PHP errors. Information may expose security risks or lead to information leakage. But during the development process, we need these error messages to locate problems and debug the program.
One way to solve this problem is to turn on PHP's error output. In PHP we can set the error log level or report errors immediately. At the same time, we can also add some options to the Nginx configuration file to display PHP error messages.
2. PHP error settings in Nginx configuration file
Open the Nginx server configuration file, usually /etc/nginx/nginx.conf
, find the http{}
block, and add the following configuration:
server { # server settings ... # server block location rules ... # php-fpm status check location ~ ^/(status|ping)$ { access_log off; # php-fpm settings fastcgi_param PHP_VALUE "error_reporting=E_ALL"; include fastcgi_params; fastcgi_pass unix:/run/php/php7.4-fpm.sock; } # php error logs location ~ \.php$ { fastcgi_param PHP_VALUE "error_log=/var/log/nginx/php_error.log"; include fastcgi_params; fastcgi_pass unix:/run/php/php7.4-fpm.sock; } # error pages error_page 404 /404.html; error_page 500 502 503 504 /50x.html; # static files location ~* \.(jpg|jpeg|gif|png|css|js|ico)$ { expires 7d; access_log off; } # disable direct access to .ht files location ~ /\.ht { deny all; } }
Among them, fastcgi_param PHP_VALUE
is used to pass error information to the PHP process requested by the Nginx server. error_reporting=E_ALL
means outputting all error level information. fastcgi_param PHP_VALUE "error_log=/var/log/nginx/php_error.log";
means outputting PHP error information to the /var/log/nginx/php_error.log
file.
After changing the configuration file, reload the Nginx server:
sudo systemctl reload nginx
3. Wrong settings in the PHP configuration file
The PHP configuration file is general For /etc/php/7.4/fpm/php.ini
, find the line error_reporting
and set it to display all error messages:
error_reporting = E_ALL
Then find display_errors
This line, set it to On
, so that all PHP error messages can be displayed on the web page:
display_errors = On
Then save the file and restart PHP- FPM:
sudo systemctl restart php7.4-fpm
4. Summary
The trick to configure the Nginx web server to prompt PHP error message hiding is to set it from both the Nginx server and the PHP process. This can help developers quickly identify errors in the code, help quickly fix problems, and improve code quality.
The above is the detailed content of How to solve nginx not prompting php error. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software