温馨提示×

debian运行laravel报错咋办

小樊
44
2026-09-14 10:05:19
栏目: 智能运维

在 Debian 上运行 Laravel 报错,原因可能很多,但绝大多数问题都集中在环境、权限和配置上。下面我按「常见报错 → 原因 → 解决办法」给你一个排错清单,你可以对照看。


一、先确认基础环境

Laravel 对环境要求比较严格:

php -v
composer -V

要求:

  • PHP ≥ 8.1(Laravel 10/11)
  • 已安装扩展:
php -m | grep -E 'mbstring|xml|bcmath|curl|json|tokenizer|sqlite|pdo'

缺少扩展就装:

sudo apt install php-mbstring php-xml php-bcmath php-curl php-sqlite3 php-mysql

二、最常见报错及解决

1️⃣ Permission denied(storage / bootstrap/cache)

报错示例:

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

解决:

cd /你的项目目录
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

2️⃣ key:generate 报错 / APP_KEY 为空

php artisan key:generate

如果报错:

  • 检查 .env 是否存在
cp .env.example .env

3️⃣ Class not found / Command not found

通常是没装依赖:

composer install

如果内存不足:

COMPOSER_MEMORY_LIMIT=-1 composer install

4️⃣ Nginx / Apache 500

Nginx 用户通常是 www-data

检查:

ps aux | grep nginx

确保项目目录权限正确(见第 2 点)


5️⃣ SQLSTATE[HY000] [2002] No such file or directory

这是 MySQL socket 问题

.env 中:

DB_HOST=127.0.0.1
DB_PORT=3306

不要用 localhost


6️⃣ Failed to open stream: Too many open files

Debian 默认限制低:

ulimit -n 65535

或改:

/etc/security/limits.conf

三、快速排错命令(必跑)

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

四、如果你愿意,我可以精准帮你

你可以直接把报错原文贴出来(红字部分),比如:

  • 终端报错
  • Nginx error.log
  • storage/logs/laravel.log

我可以一行一行帮你定位 ✅

0