在 Debian 上调试 Laravel,通常可以从**环境准备、日志与错误显示、调试工具、IDE 调试(Xdebug)**几个方面入手。下面给你一套比较实用的做法。
确保你已经安装并正确配置:
php -v
composer -V
mysql -V # 或 mariadb
nginx -v # 或 apache2 -v
Laravel 所需 PHP 扩展(常见):
sudo apt install php-cli php-mbstring php-xml php-curl php-mysql php-zip php-bcmath php-gd
.envAPP_DEBUG=true
APP_ENV=local
php artisan config:clear
php artisan cache:clear
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/php8.2-fpm.log
sudo tail -f /var/log/apache2/error.log
dump() / dd()dump($user);
dd($request->all());
\Log::error('调试信息', ['data' => $data]);
查看日志:
tail -f storage/logs/laravel.log
php artisan tinker
示例:
User::first();
App\Models\Order::where('status', 'paid')->count();
非常适合调试 Model / 查询。
sudo apt install php-xdebug
查看版本:
php -m | grep xdebug
编辑:
sudo nano /etc/php/8.2/cli/conf.d/20-xdebug.ini
内容示例:
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
重启服务:
sudo systemctl restart php8.2-fpm
launch.json{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
]
}
然后:
✅ .env 是否存在
✅ storage 和 bootstrap/cache 权限
sudo chown -R www-data:www-data storage bootstrap/cache
✅ 路由是否存在
php artisan route:list
✅ 数据库是否连接
php artisan tinker
DB::connection()->getPdo();
新手:
APP_DEBUG=true + dd() + laravel.log
进阶:
tinker + Log::
专业:
Xdebug + VS Code / PHPStorm
如果你愿意,可以告诉我:
我可以直接给你一份可用的配置文件。