温馨提示×

debian下laravel报错咋解决

小樊
50
2026-09-08 06:44:20
栏目: 智能运维

在 Debian 下运行 Laravel 报错很常见,但具体解决方法取决于报错内容。下面我按「常见错误类型 → 原因 → 解决办法」给你一个排查清单,你对着看基本能解决 90% 的问题。


一、最常用排查命令(一定要先看)

php artisan
php -v
composer -V
tail -f storage/logs/laravel.log

二、常见报错及解决办法

1️⃣ The stream or file "/var/www/.../storage/logs/laravel.log" could not be opened

原因:权限不足
解决

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

2️⃣ Class "XXX" not found

原因

  • Composer 没装完
  • 自动加载失效

解决

composer install
composer dump-autoload

3️⃣ PHP Missing extensions (mbstring, xml, gd, curl...)

Debian 常见

解决

sudo apt install php-mbstring php-xml php-curl php-gd php-zip php-bcmath
sudo systemctl restart apache2   # 或 php-fpm

4️⃣ SQLSTATE[HY000] [2002] Connection refused

原因:数据库没连上

检查

sudo systemctl status mysql

.env 示例:

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

5️⃣ Permission denied (public key)(Git/Composer)

解决

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub

贴到 GitHub / GitLab


6️⃣ 419 Page Expired

原因:CSRF 或 session 权限

解决

php artisan config:clear
php artisan cache:clear
chmod -R 755 storage

7️⃣ Apache / Nginx 空白页

Apache

sudo a2enmod rewrite
sudo systemctl restart apache2

Nginx 示例

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

三、建议你这样发报错,我可以直接帮你定位

你可以直接贴:

  • 完整报错信息
  • php -v
  • Debian 版本(cat /etc/os-release
  • Web 服务(Apache / Nginx)
  • Laravel 版本

例如:

Debian 11 + Nginx + PHP 8.1 + Laravel 10
报错:Class “Redis” not found

我可以一步一步给你命令

你现在是遇到哪一种报错?

0