在 Ubuntu 上,PHP-FPM 的日志位置和查看方式主要取决于你用的是哪个 PHP 版本以及FPM 的配置。下面按常见情况说明。
PHP-FPM 一般有两类日志:
php -v
# 或
ls /etc/php/
例如:
/etc/php/7.4/
/etc/php/8.1/
打开 FPM 配置文件:
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 版本 | 默认日志路径 |
|---|---|
| 7.4 | /var/log/php7.4-fpm.log |
| 8.1 | /var/log/php8.1-fpm.log |
| 8.2 | /var/log/php8.2-fpm.log |
sudo tail -f /var/log/php8.1-fpm.log
php --ini
或:
sudo nano /etc/php/8.1/fpm/php.ini
查找:
log_errors = On
error_log = /var/log/php_errors.log
如果没设置,PHP 错误可能:
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/apache2/error.log
systemctl status php8.1-fpm
重启 FPM(改配置后):
sudo systemctl restart php8.1-fpm
# 查看 FPM 配置
php-fpm8.1 -t
# 查看日志
sudo tail -f /var/log/php8.1-fpm.log
# Nginx 错误
sudo tail -f /var/log/nginx/error.log
如果你愿意,可以告诉我:
我可以直接帮你定位日志和原因。