在 Debian 上调试 Laravel 应用,通常可以从**环境准备、日志、调试工具、IDE 调试(Xdebug)**几个方面入手。下面给你一套比较实用的做法。
sudo apt update
sudo apt install -y php php-cli php-common php-mbstring php-xml php-curl php-mysql php-zip unzip git
如果使用 Nginx/Apache:
sudo apt install -y nginx php-fpm
# 或
sudo apt install -y apache2 libapache2-mod-php
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
编辑 .env:
APP_DEBUG=true
APP_ENV=local
⚠️ 生产环境务必关闭 APP_DEBUG
dump() / dd()dump($user);
dd($request->all());
tail -f storage/logs/laravel.log
常见错误:
php artisan route:list
php artisan migrate:status
php artisan config:clear
php artisan cache:clear
php artisan serve
sudo apt install php-xdebug
确认:
php -m | grep xdebug
编辑:
sudo nano /etc/php/8.2/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
xdebug.idekey=PHPSTORM
重启 PHP:
sudo systemctl restart php8.2-fpm
9003PHPSTORMphp artisan tinker
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
php -v
which php
确保 CLI 和 Web 使用同一 PHP 版本
sudo systemctl status mysql
mysql -u root -p
✅ 开发环境:
APP_DEBUG=truetail -f laravel.log✅ 生产环境:
APP_DEBUG=false如果你愿意,可以告诉我:
我可以给你更精确的 Debian + Laravel 调试方案。