温馨提示×

debian下laravel报错怎么解

小樊
36
2026-10-22 19:40:53
栏目: 智能运维

在 Debian 下运行 Laravel 报错的“原因很多”,通常可以按 报错类型 来快速定位。下面给你一套通用排查流程 + 常见错误及解决办法,你可以对照看。


一、先做的通用排查(90%问题在这里)

1️⃣ 看真实报错信息

tail -f storage/logs/laravel.log

或访问页面时打开:

APP_DEBUG=true

2️⃣ 权限问题(Debian 最常见)

Laravel 需要写 storage 和 bootstrap/cache

sudo chown -R www-data:www-data /var/www/your-project
sudo chmod -R 755 storage bootstrap/cache

如果你是 CLI 运行:

sudo chown -R $USER:www-data storage

3️⃣ PHP 版本 & 扩展

Laravel 10+ 需要 PHP 8.1+

检查:

php -v
php -m | grep -E "mbstring|xml|ctype|json|tokenizer|bcmath|openssl"

缺扩展就装:

sudo apt install php8.2-mbstring php8.2-xml php8.2-bcmath php8.2-curl

4️⃣ Composer 依赖没装

composer install
composer dump-autoload

二、Debian 下常见 Laravel 报错 & 解决

❌ 1. The stream or file "/storage/logs/laravel.log" could not be opened

✅ 权限问题

chmod -R 775 storage
chown -R www-data:www-data storage

❌ 2. SQLSTATE[HY000] [2002] Connection refused

✅ 数据库问题

sudo systemctl status mysql

.env 检查:

DB_HOST=127.0.0.1
DB_PORT=3306

❌ 3. Class "XXX" not found

✅ 自动加载坏了

composer dump-autoload

❌ 4. Permission denied (public key)(Git/Deploy)

ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519.pub

加到 Git 服务器


❌ 5. Nginx 502 / 空白页

sudo apt install php8.2-fpm
sudo systemctl restart php8.2-fpm
sudo systemctl restart nginx

三、如果你愿意,我可以直接帮你定位

你可以把 具体报错信息(哪怕是截图文字)发给我,例如:

  • 浏览器报错
  • laravel.log 内容
  • php artisan 报错

我可以精确到哪一行配置或命令帮你改。

你现在是 本地 / 服务器 / Docker 环境?

0 踩