定位与查看日志
sudo tail -n200 /var/log/php-fpm/error.logsudo tail -n200 /var/log/nginx/error.logdisplay_errors = On、log_errors = On、error_reporting = E_ALLtry_files $uri $uri/ /index.php$is_args$args;sudo systemctl restart php-fpm 或 sudo systemctl restart nginx / sudo systemctl restart httpddisplay_errors = Off,避免泄露敏感信息。常见错误模式与修复要点
open_basedir 限制导致文件包含失败
Warning: require(): open_basedir restriction in effect. File(...) is not within the allowed path(s): ...Fatal error: require(): Failed opening required '.../thinkphp/start.php'PHP_ADMIN_VALUE "open_basedir=...",把项目根目录加入白名单,例如:
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/www/wwwroot/:/tmp/:/proc/";(路径按实际修改)open_basedir 限制(仅在可信环境)。函数被禁用导致功能异常
scandir() has been disabled for security reasonsscandir、exec、shell_exec 等)。disable_functions 中移除业务必需的函数(如 scandir),保存后重启 PHP-FPM:sudo systemctl restart php-fpm。URL 重写导致 404 或入口未命中
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
sudo systemctl restart nginx。500 错误但页面空白
display_errors,获取更详细的堆栈信息。memory_limit、max_execution_time),必要时适当调高并重启服务。高效排查流程与命令清单
tail -f 实时查看 Nginx 与 PHP-FPM 错误日志 → 3) 根据关键词锁定阶段(Web 接入、PHP 解析、框架分发)→ 4) 对照常见模式修复 → 5) 回归关闭详细输出并持续观察。sudo systemctl status php-fpm nginx httpdsudo systemctl restart php-fpm / sudo systemctl restart nginx / sudo systemctl restart httpdsudo tail -f /var/log/php-fpm/error.log;sudo tail -f /var/log/nginx/error.log日志字段解读与快速判断
in /www/wwwroot/.../public/index.php on line 16,优先检查该行及其包含/引入的文件是否存在、是否可读。Fatal error、Parse error、Warning,分别对应致命错误、语法解析错误、警告;致命错误会中止脚本执行。open_basedir restriction in effect、has been disabled for security reasons,分别对应路径白名单与函数禁用策略,需要到 PHP 配置或 FPM fastcgi 参数中调整。connect() to unix:/run/php-fpm.sock failed,多为 PHP-FPM 未运行或 Nginx 与 PHP-FPM 通信配置不一致(socket 路径、权限)。