调试 Debian 上的 Laravel,通常分为 环境层面、Laravel 自身、日志与工具 三个层面。下面给你一套从“新手可用”到“进阶定位问题”的完整思路。
Laravel 对 PHP 版本要求严格:
php -v
常见缺失扩展:
sudo apt install php php-cli php-common php-mysql php-mbstring php-xml php-curl php-zip php-bcmath php-tokenizer
✅ 建议:
composer -V
composer install
常见问题:
composer install 报权限错误 → 不要用 root 直接跑php -d memory_limit=-1 /usr/bin/composer install
sudo systemctl status nginx
sudo systemctl status php8.2-fpm
Nginx 示例配置(关键):
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
编辑 .env:
APP_DEBUG=true
APP_ENV=local
⚠️ 生产环境不要用
tail -f storage/logs/laravel.log
常见错误:
SQLSTATE[HY000] [2002] → 数据库没启动Permission denied → storage / bootstrap 权限问题sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
如果你是普通用户开发:
sudo usermod -aG www-data $USER
sudo systemctl status mariadb
# 或 mysql
php artisan tinker
DB::connection()->getPdo();
php artisan route:list
dd($data);
dump($data);
composer require barryvdh/laravel-debugbar --dev
访问页面后,底部会出现调试栏。
sudo apt install php-xdebug
xdebug.mode=develop,debug
xdebug.start_with_request=yes
配合:
APP_DEBUG=truestorage/logs/laravel.log/var/log/nginx/error.log/var/log/php8.2-fpm.logphp artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan optimize:clear
你可以直接贴:
我可以一步一步帮你精确到“哪一行代码出问题”。