在 Debian 上调试 Laravel 程序,通常可以从**环境准备、日志与错误显示、调试工具、IDE 调试(Xdebug)**几个方面入手。下面给你一套实用流程。
sudo apt update
sudo apt install -y php php-cli php-fpm php-mysql php-mbstring php-xml php-curl php-zip unzip git nginx
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
php -v
Laravel 不同版本对 PHP 有要求(如 Laravel 10 需要 PHP 8.1+)。
.envAPP_DEBUG=true
APP_ENV=local
php artisan config:clear
php artisan cache:clear
tail -f storage/logs/laravel.log
# PHP-FPM
tail -f /var/log/php*-fpm.log
# Nginx
tail -f /var/log/nginx/error.log
dump() / dd()dump($user);
dd($request->all());
php artisan route:list
php artisan tinker
php artisan migrate:status
\DB::enableQueryLog();
// 执行查询
dump(\DB::getQueryLog());
sudo apt install php-xdebug
编辑 php.ini 或 /etc/php/*/cli/conf.d/20-xdebug.ini:
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
sudo systemctl restart php*-fpm
Listen for Xdebug| 问题 | 排查方式 |
|---|---|
| 500 错误 | 看 laravel.log |
| 路由不存在 | php artisan route:list |
| 数据库连接失败 | 检查 .env + php artisan migrate |
| 页面空白 | 开 APP_DEBUG=true |
| 慢查询 | DB::enableQueryLog() |
tail -f storage/logs/laravel.log如果你愿意,可以告诉我:
我可以直接帮你定位问题。