在 Debian 上运行 Laravel 报错,原因可能很多,但绝大多数问题都集中在环境、权限和配置上。下面我按「常见报错 → 原因 → 解决办法」给你一个排错清单,你可以对照看。
Laravel 对环境要求比较严格:
php -v
composer -V
要求:
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
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
key:generate 报错 / APP_KEY 为空php artisan key:generate
如果报错:
.env 是否存在cp .env.example .env
Class not found / Command not found通常是没装依赖:
composer install
如果内存不足:
COMPOSER_MEMORY_LIMIT=-1 composer install
Nginx 用户通常是 www-data
检查:
ps aux | grep nginx
确保项目目录权限正确(见第 2 点)
SQLSTATE[HY000] [2002] No such file or directory这是 MySQL socket 问题
.env 中:
DB_HOST=127.0.0.1
DB_PORT=3306
不要用 localhost
Failed to open stream: Too many open filesDebian 默认限制低:
ulimit -n 65535
或改:
/etc/security/limits.conf
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
你可以直接把报错原文贴出来(红字部分),比如:
error.logstorage/logs/laravel.log我可以一行一行帮你定位 ✅