在 Ubuntu 上排查 PHP 日志,通常可以从 PHP 自身错误日志、Web 服务器(Nginx/Apache)日志、应用框架日志 三个层面入手。下面按实用顺序说明。
php --ini
或
php -i | grep "Loaded Configuration File"
查看以下两项:
log_errors = On
error_log = /var/log/php/php_errors.log
如果 error_log 为空,PHP 通常会把错误输出到 Web 服务器日志。
/var/log/php*/php-fpm.log
/var/log/php*/www-error.log
例如:
/var/log/php8.1-fpm.log
/var/log/php8.1-fpm/www-error.log
/var/log/apache2/error.log
/var/log/nginx/error.log
/var/log/php*/www-error.log
tail -f /var/log/php8.1-fpm/www-error.log
或:
tail -f /var/log/nginx/error.log
访问页面,观察报错。
编辑 php.ini:
display_errors = On
error_reporting = E_ALL
重启:
systemctl restart php8.1-fpm
看:
/var/log/nginx/error.log
/var/log/php*/www-error.log
常见原因:
display_errors 没开解决:
tail -f /var/log/php*/www-error.log
Permission denied
检查:
ls -l /var/www/html
ps aux | grep php-fpm
PHP 运行用户(如 www-data)需有读/写权限。
日志中常见:
Allowed memory size exhausted
Maximum execution time exceeded
调整:
memory_limit = 256M
max_execution_time = 120
storage/logs/laravel.log
runtime/log/
# 1. 看 PHP 日志
tail -f /var/log/php*/www-error.log
# 2. 看 Web 服务日志
tail -f /var/log/nginx/error.log
# 3. 检查 PHP 是否运行
systemctl status php8.1-fpm
# 4. 检查语法
php -l index.php
如果你能提供:
我可以给你更精确的排查方案。