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 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.

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.

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.

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

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).

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.
