nginx php-fpm output php error log
nginx is a web server, so the access log of nginx only records the accessed pages, and there will be no error log information of php.
nginx sends the request for php to the php-fpm fastcgi process for processing. The default php-fpm will only output the error message of php-fpm, and php cannot be seen in the errors log of php-fpm. The reason for the errorlog
is that the php-fpm configuration file php-fpm.conf defaults to turning off the error output of the worker process and redirecting them directly to /dev/null, so we use nginx’s error log and The error log of php-fpm cannot be seen in the error log of php.
Debugging is very painful. Ways to solve the problem that php-fpm does not record php error logs under nginx:
1. Modify the configuration in php-fpm.conf and add
catch_workers_output = yes error_log = log/error_log
2. Modify the configuration in php.ini, if not, add
log_errors = On error_log = "/usr/local/lnmp/php/var/log/error_log" error_reporting=E_ALL&~E_NOTICE
3. Restart php-fpm
You can see it when PHP execution errors The error log is in "/usr/local/lnmp/php/var/log/error_log"
Please note:
1. php-fpm.conf The php_admin_value[error_log] parameter in php.ini will override the error_log parameter in php.ini
So make sure the final error_log file you see in phpinfo() has writable permissions and does not set the php_admin_value[error_log] parameter, otherwise the error log will Output to the error log of php-fpm.
2. The location of php.ini cannot be found, use php's phpinfo() to view the results
3. How to modify the PHP error log not to be output to the page or screen
Modify php.ini
display_errors = off //不显示错误信息(不输出到页面或屏幕上) log_errors = on //记录错误信息(保存到日志文件中) error_reporting = E_ALL //捕获所有错误信息 error_log = //设置日志文件名
Modify the above configuration in the program
ini_set("display_errors",0) ini_set("error_reporting",E_ALL); //这个值好像是个PHP的常量 ini_set("error_log","<日志文件名>") ini_set("log_errors",1);
4. How to output the php error log to the nginx error log
In PHP 5.3.8 and earlier versions, when PHP runs through FastCGI and an error occurs during user access, it will first be written to PHP's errorlog.
If PHP's errorlog cannot be written, the error content will be returned. Give the FastCGI interface, and then nginx records it in the nginx errorlog after receiving the error return from FastCGI
In PHP 5.3.9 and later versions, PHP only tries to write to the PHP errorlog after an error occurs. If it fails, There will no longer be a return to FastCGI, the error log will be output to the error log of php-fpm.
So if you want to output the php error log to the nginx error log, you need to use a version before php5.3.8, and the error_log of php in the configuration file is not writable by the php worker process.
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of nginx php-fpm output php error log. 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)

Hot Topics











How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

When the Nginx server goes down, you can perform the following troubleshooting steps: Check that the nginx process is running. View the error log for error messages. Check the syntax of nginx configuration. Make sure nginx has the permissions you need to access the file. Check file descriptor to open limits. Confirm that nginx is listening on the correct port. Add firewall rules to allow nginx traffic. Check reverse proxy settings, including backend server availability. For further assistance, please contact technical support.
