解决 Debian 上 Laravel 报错,通常可以按**“先定位错误 → 再按类别解决”的思路来。下面我给你一个实用排查清单**,覆盖最常见的情况。
tail -f storage/logs/laravel.log
APP_DEBUG=true
⚠️ 生产环境不要开启
PHP Fatal error: Class 'XXX' not found
或
Your requirements could not be resolved to an installable set of packages.
sudo apt update
sudo apt install -y \
php php-cli php-fpm \
php-mysql php-xml php-mbstring \
php-curl php-zip php-tokenizer \
php-bcmath php-gd
Laravel 10+ 需要 PHP ≥ 8.1
查看 PHP 版本:
php -v
Class not found
Script @php artisan package:discover handling the post-autoload-dump event returned with error 255
composer install --no-dev
composer dump-autoload
如果是版本冲突:
composer update
The stream or file could not be opened
Permission denied
sudo chown -R www-data:www-data /var/www/laravel
sudo chmod -R 755 /var/www/laravel
sudo chmod -R 777 storage bootstrap/cache
如果你用
php artisan serve,当前用户也要有权限
SQLSTATE[HY000] [2002] No such file or directory
Debian 默认 MySQL socket 路径不同
.envDB_HOST=127.0.0.1
DB_PORT=3306
或确认 socket:
mysql -u root -p
server {
listen 80;
server_name your_domain;
root /var/www/laravel/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
然后:
sudo systemctl restart nginx
sudo systemctl restart php-fpm
php artisan cache:clear
php artisan config:clear
php artisan route:clear
PHP Warning: date()
sudo dpkg-reconfigure locales
sudo apt install locales
PHP:
date.timezone = Asia/Shanghai
php -v
composer -V
php artisan --version
systemctl status nginx
systemctl status mysql
你可以直接把 完整报错信息 发给我,例如:
laravel.log 内容我可以逐行帮你定位并给出精确命令 ✅