在 Debian 下运行 Laravel 报错很常见,但具体解决方法取决于报错内容。下面我按「常见错误类型 → 原因 → 解决办法」给你一个排查清单,你对着看基本能解决 90% 的问题。
php artisan
php -v
composer -V
tail -f storage/logs/laravel.log
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
Class "XXX" not found原因:
解决:
composer install
composer dump-autoload
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
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=
Permission denied (public key)(Git/Composer)解决:
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub
贴到 GitHub / GitLab
419 Page Expired原因:CSRF 或 session 权限
解决:
php artisan config:clear
php artisan cache:clear
chmod -R 755 storage
Apache
sudo a2enmod rewrite
sudo systemctl restart apache2
Nginx 示例
location / {
try_files $uri $uri/ /index.php?$query_string;
}
你可以直接贴:
php -vcat /etc/os-release)例如:
Debian 11 + Nginx + PHP 8.1 + Laravel 10
报错:Class “Redis” not found
我可以一步一步给你命令。
你现在是遇到哪一种报错?