在 CentOS 上调试 Laravel,通常可以从 日志、错误显示、调试工具、运行环境 几个方面入手。下面按「最常用 → 进阶」的顺序说明。
编辑 .env:
APP_ENV=local
APP_DEBUG=true
然后清缓存:
php artisan config:clear
php artisan cache:clear
⚠️ 生产环境一定要
APP_DEBUG=false
tail -f storage/logs/laravel.log
常见错误:
dd() / dump()dd($user);
// 或
dump($request->all());
chown -R nginx:nginx /var/www/laravel
chmod -R 755 /var/www/laravel
chmod -R 777 storage bootstrap/cache
nginx 或 apache 用户需可写
storage
tail -f /var/log/php-fpm/error.log
或 Apache:
tail -f /var/log/httpd/error_log
php -v
php -m | grep -E "mbstring|openssl|pdo|tokenizer"
Laravel 必需扩展:
DB::enableQueryLog();
// 执行查询
dd(DB::getQueryLog());
或使用:
\Log::info(DB::getQueryLog());
php artisan tinker
DB::connection()->getPdo();
php artisan route:list
php artisan serve
然后访问:
http://localhost:8000/your-route
安装:
yum install php-xdebug
配置 /etc/php.d/xdebug.ini:
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
配合 PHPStorm + Xdebug 可断点调试。
composer require barryvdh/laravel-debugbar --dev
访问页面即可看到:
| 问题 | 解决 |
|---|---|
| 500 错误 | 看 laravel.log |
| 空白页 | APP_DEBUG=true |
| Permission denied | 改 storage 权限 |
| Class not found | composer dump-autoload |
| SQLSTATE[HY000] | 检查 .env 数据库配置 |
如果你愿意,可以告诉我:
我可以给你 更精确的调试方案。