在 Debian 下运行 Laravel 报错是很常见的情况,通常和权限、PHP 版本、依赖、配置有关。下面按「最常见问题 → 排查步骤 → 常见报错及解决办法」给你一个实用指南。
在 Debian 上先检查:
php -v
composer -V
nginx -v # 或 apache2 -v
Laravel 对 PHP 版本有要求(例如 Laravel 10 需要 PHP 8.1+)。
The stream or file "/storage/logs/laravel.log" could not be opened原因:storage / bootstrap 目录权限不对
解决:
cd /var/www/your-project
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
Class 'XXX' not found / 页面 500原因:依赖没装或 autoload 坏了
解决:
composer install
composer dump-autoload
SQLSTATE[HY000] [2002] No such file or directory原因:MySQL 没启动或 .env 配置错
解决:
sudo systemctl status mysql
sudo systemctl start mysql
.env 示例:
DB_HOST=127.0.0.1
DB_PORT=3306
key:generate 报错 / APP_KEY 为空cp .env.example .env
php artisan key:generate
原因:重写规则没配
Nginx 配置示例:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
常见缺失扩展:
sudo apt install php-mysql php-mbstring php-xml php-curl php-zip php-bcmath
然后:
sudo systemctl restart php8.1-fpm
tail -f storage/logs/laravel.log
APP_DEBUG=true
php artisan config:clear
php artisan cache:clear
php artisan route:clear
你可以把具体报错信息贴出来(哪怕一行也行),比如:
laravel.log 内容我可以直接告诉你是 Debian 环境问题还是 Laravel 代码问题,并给精准命令。