在 Ubuntu 下让 PHP 显示错误提示,通常分 CLI(命令行) 和 Web(Apache/Nginx) 两种情况。
php --ini
或
php -i | grep "Loaded Configuration File"
常见路径:
/etc/php/8.1/apache2/php.ini/etc/php/8.1/cli/php.ini/etc/php/8.1/fpm/php.inidisplay_errors = On
display_startup_errors = On
error_reporting = E_ALL
⚠️ 生产环境不建议
display_errors = On
# Apache
sudo systemctl restart apache2
# Nginx + PHP-FPM
sudo systemctl restart php8.1-fpm
sudo systemctl restart nginx
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
log_errors = On
error_log = /var/log/php_errors.log
查看日志:
tail -f /var/log/php_errors.log
说明 display_errors 仍是 Off,看日志最快
如果你用的是 Apache / Nginx / Laravel,可以告诉我,我可以给你更具体的配置。