先查看 storage/logs/laravel.log 是否有报错内容,绝大多数500错误的异常堆栈都记录于此;若文件为空或不存在,说明 storage 目录无写权限,需确保 storage 和 bootstrap/cache 属主为 www:www、目录权限775、文件权限664,并开启 app_debug=true 辅助定位。

先看 storage/logs/laravel.log 有没有报错内容
绝大多数 500 错误背后都有明确的异常堆栈,就藏在 storage/logs/laravel.log 里。这个文件是 Laravel 默认日志输出位置,只要 PHP 进程有写权限、APP_DEBUG=false,它就是第一手线索。
常见现象:
- 文件为空或根本不存在 → 权限问题(
storage目录没被www用户写入) - 日志里出现
The stream or file "/path/to/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied→ 立刻检查storage和bootstrap/cache目录权限 - 日志里有
Class '...' not found或Call to undefined function openssl_random_pseudo_bytes()→ 缺扩展或自动加载失效
实操建议:
- 用
ls -l storage/logs/确认laravel.log所属用户组是否为www(宝塔/Nginx 常用用户) - 如果文件不存在,手动创建并赋权:
touch storage/logs/laravel.log && chown www:www storage/logs/laravel.log - 别直接
chmod 777 storage,最小权限原则:目录 775,文件 664
APP_DEBUG=true 必须开,但只在非生产环境
不开 APP_DEBUG,Laravel 就不会把错误详情渲染到页面,你只会看到一个干巴巴的 500 —— 这不是隐藏错误,是主动屏蔽线索。
关键点:
-
.env中设为APP_DEBUG=true后,无需重启 PHP-FPM 或 Nginx,改完保存即生效 - 线上环境绝对不能开,否则敏感配置、SQL、路径全暴露
- 如果开了仍看不到错误页面,说明请求根本没进 Laravel(比如 Nginx 配置拦截了,或 ModSecurity/WAF 拦截了)
验证方式:访问任意一个明显会出错的路由(比如故意在控制器里写 throw new Exception('test')),看是否显示完整异常页面。
检查 Nginx/Apache 的错误日志,尤其是 FastCGI stderr
当 laravel.log 没内容、APP_DEBUG=true 也不显示错误时,说明 PHP 进程在进入 Laravel 之前就崩了。这时候 Web 服务器日志才是真相出口。
重点关注:
- Nginx 错误日志中的
FastCGI sent in stderr行,它直接转发 PHP 解析失败、扩展缺失、语法错误等底层报错 - Apache 的
error_log里类似PHP Fatal error: Uncaught Error:的条目 - 阿里云/腾讯云用户特别注意:WAF 或安全组可能返回 403 或静默拦截,错误日志里会出现
ModSecurity: Access denied
典型错误示例:
-
PHP Fatal error: Call to undefined function mb_strlen()→ 缺mbstring扩展 -
PHP Parse error: syntax error, unexpected '?'→ PHP 版本低于 7.0(Laravel 8+ 要求 7.3+) -
Primary script unknown→root或fastcgi_param SCRIPT_FILENAME路径配置错误
确认 storage 和 bootstrap/cache 可写,且属主正确
这两个目录是 Laravel 运行时必须写入的,权限不对会导致框架启动失败,直接 500,连日志都写不进去。
不要用 777,真实有效的权限组合是:
-
storage和bootstrap/cache目录:775,属主属组为www:www(宝塔默认)或www-data:www-data(Ubuntu 默认) - 目录内已有文件(如
storage/app/.gitignore):664 - 新生成的缓存文件(如
bootstrap/cache/packages.php):由 PHP 进程自动创建,属主必须是运行用户
执行命令参考(以宝塔为例):
chown -R www:www storage bootstrap/cache
find storage -type d -exec chmod 775 {} \;
find storage -type f -exec chmod 664 {} \;
find bootstrap/cache -type d -exec chmod 775 {} \;
find bootstrap/cache -type f -exec chmod 664 {} \;
如果用了 Docker 或 SELinux,还要额外检查上下文标签或挂载权限,这点容易被跳过。











