在 Debian 下运行 Laravel 时,错误种类很多,下面按最常见问题 → 排查步骤 → 解决办法来说明,你可以对照自己的情况。
在 Debian 上先执行:
php -v
php -m
composer -V
确认:
mbstring、xml、curl、zip、gd、sqlite/mysql pdo 等扩展如果缺扩展:
sudo apt install php-mbstring php-xml php-curl php-zip php-gd php-mysql
sudo systemctl restart apache2 # 或 php-fpm
The stream or file "/storage/logs/laravel.log" could not be opened原因:权限不足
解决:
sudo chown -R www-data:www-data /var/www/your-project
sudo chmod -R 755 storage bootstrap/cache
SQLSTATE[HY000] [2002] Connection refused原因:数据库未启动或配置错误
检查:
sudo systemctl status mysql
.env 中:
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=xxx
DB_USERNAME=xxx
DB_PASSWORD=xxx
修改后:
php artisan config:clear
Class 'XXX' not found / Composer autoload 错误原因:依赖未安装或自动加载损坏
解决:
composer install
composer dump-autoload
Permission denied (public key)(Git / Composer)Debian 下常见:
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub
添加到 GitHub / GitLab
Apache: 确保启用了 mod_rewrite:
sudo a2enmod rewrite
sudo systemctl restart apache2
Nginx 示例:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
如果只看到 500:
tail -f storage/logs/laravel.log
或临时开启调试(.env):
APP_DEBUG=true
APP_ENV=local
✅ PHP 版本正确
✅ 扩展齐全
✅ storage / bootstrap 可写
✅ .env 存在且正确
✅ 数据库已启动
✅ composer 已安装依赖
请把具体错误信息贴出来(终端或 laravel.log 内容),例如:
我可以直接告诉你是哪一行配置或权限的问题。