在 Ubuntu 下,php-fpm 的日志主要分为两类:
下面按常见场景说明。
php -v
# 例如 PHP 8.1
ls /etc/php/
常见路径:
/etc/php/8.1/fpm/
主配置:
/etc/php/8.1/fpm/php-fpm.conf
池配置(最重要):
/etc/php/8.1/fpm/pool.d/www.conf
编辑:
sudo nano /etc/php/8.1/fpm/pool.d/www.conf
关键配置:
catch_workers_output = yes
php_admin_value[error_log] = /var/log/php8.1-fpm.log
php_admin_flag[log_errors] = on
或全局:
error_log = /var/log/php8.1-fpm.log
重启 php-fpm:
sudo systemctl restart php8.1-fpm
查看日志:
sudo tail -f /var/log/php8.1-fpm.log
sudo nano /etc/php/8.1/fpm/php.ini
log_errors = On
error_log = /var/log/php_errors.log
创建日志文件:
sudo touch /var/log/php_errors.log
sudo chown www-data:www-data /var/log/php_errors.log
重启:
sudo systemctl restart php8.1-fpm
用于排查 PHP 执行慢的问题。
在 www.conf 中:
request_slowlog_timeout = 5s
slowlog = /var/log/php8.1-fpm-slow.log
重启:
sudo systemctl restart php8.1-fpm
查看:
sudo tail -f /var/log/php8.1-fpm-slow.log
/var/log/nginx/error.log
/var/log/nginx/access.log
display_errors = Off(生产环境)log_errors = Onerror_log 路径可写sudo chown -R www-data:www-data /var/log/php*
# 查看 php-fpm 状态
systemctl status php8.1-fpm
# 实时看日志
tail -f /var/log/php8.1-fpm.log
tail -f /var/log/php_errors.log
如果你愿意,可以告诉我:
我可以给你更精确的配置。