在 Ubuntu 上排查 PHP 日志报错,通常可以按下面几个步骤来:
不同运行方式,日志位置不一样:
ps aux | grep php-fpm
apache2ctl -M | grep php
命令行直接运行时的错误会直接输出在终端。
php --ini
常见路径:
/etc/php/8.1/fpm/php.ini/etc/php/8.1/cli/php.ini查看错误日志配置:
grep -E "error_log|log_errors|display_errors" /etc/php/8.1/fpm/php.ini
关键参数:
log_errors = On
error_log = /var/log/php/php-fpm.log
display_errors = Off
/var/log/php*/php-fpm.log
或:
/var/log/php-fpm.log
/var/log/nginx/error.log
/var/log/apache2/error.log
很多框架会自己写日志:
storage/logs/laravel.logruntime/log/wp-content/debug.logtail -f /var/log/php/php-fpm.log
tail -f /var/log/nginx/error.log
只查看报错:
tail -f /var/log/nginx/error.log | grep error
| 报错 | 说明 |
|---|---|
Permission denied |
文件/目录权限问题 |
Class not found |
自动加载或命名空间错误 |
Allowed memory size exhausted |
内存不足 |
Failed to open stream |
文件路径错误 |
SQLSTATE |
数据库错误 |
编辑 php.ini:
display_errors = On
error_reporting = E_ALL
重启服务:
systemctl restart php8.1-fpm
display_errors 复现问题如果你愿意,可以把具体报错内容或**运行环境(Nginx/Apache/PHP 版本)**发出来,我可以直接帮你定位问题。