在 Ubuntu 上让 PHP-FPM 显示错误,通常需要从 PHP 配置 和 Nginx/Apache 两方面检查。下面以 Nginx + PHP-FPM 为例说明。
php --ini
或在 PHP 中输出:
<?php phpinfo(); ?>
通常路径是:
/etc/php/8.1/fpm/php.ini
(版本号可能是 7.4 / 8.0 / 8.2 等)
编辑配置文件:
sudo nano /etc/php/8.1/fpm/php.ini
确保以下配置为:
display_errors = On
display_startup_errors = On
error_reporting = E_ALL
⚠️ 生产环境不建议
display_errors = On
sudo systemctl restart php8.1-fpm
Nginx 本身不会屏蔽错误,但要确认:
fastcgi_intercept_errors off;
示例:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_intercept_errors off;
}
sudo nginx -t
sudo systemctl reload nginx
如果无法改 php.ini,可在 PHP 文件最前面写:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
display_errors = Off
log_errors = On
error_log = /var/log/php/php-error.log
查看日志:
tail -f /var/log/php/php-error.log
✅ 白屏 / 500
→ 看 PHP-FPM 日志
sudo tail -f /var/log/php8.1-fpm.log
✅ 改了不生效
→ 确认改的是 fpm/php.ini,不是 cli/php.ini
如果你用的是 Apache + PHP-FPM 或 Ubuntu 特定版本,可以告诉我,我给你对应命令。