温馨提示×

centos中laravel怎样调试

小樊
34
2026-10-11 17:08:06
栏目: 智能运维

在 CentOS 环境下调试 Laravel,通常从「日志、错误显示、调试工具、运行环境」几个方面入手。下面按实用顺序给你一套常见做法。


一、先确认基础环境(很重要)

1. 查看 PHP / Composer 版本

php -v
composer -V

2. 确认 Laravel 版本

php artisan --version

二、开启 Laravel 错误显示(最常用)

1. 修改 .env

APP_DEBUG=true
APP_ENV=local

2. 清缓存(CentOS 上经常忘)

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

三、查看日志(CentOS 服务器首选)

Laravel 日志位置

storage/logs/laravel.log

实时查看:

tail -f storage/logs/laravel.log

PHP 错误日志

/var/log/php-fpm/error.log
# 或
/var/log/httpd/error_log

四、命令行调试(非常推荐)

1. 使用 dump() / dd()

dd($request->all());

2. Artisan 调试

php artisan route:list
php artisan tinker

五、使用 Laravel Debugbar(强烈推荐)

安装

composer require barryvdh/laravel-debugbar --dev

发布配置

php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"

浏览器打开页面即可看到 SQL、请求、日志等信息。


六、Xdebug(CentOS 高级调试)

1. 安装 Xdebug

yum install php-xdebug
# 或
pecl install xdebug

2. 配置 php.ini

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003

3. 配合 PHPStorm / VSCode 断点调试


七、常见问题(CentOS 特有)

1. 权限问题

chown -R nginx:nginx storage bootstrap/cache
chmod -R 775 storage bootstrap/cache

2. SELinux 导致写不了日志

setenforce 0
# 或
setsebool -P httpd_unified 1

八、快速排查清单 ✅

  • [ ] .env 中 APP_DEBUG=true
  • [ ] 清过缓存
  • [ ] 看了 laravel.log
  • [ ] 用 dd() 或 tinker
  • [ ] 权限 / SELinux 正常

如果你愿意,可以告诉我:

  • CentOS 版本(7 / 8 / Stream)
  • PHP 版本
  • 是 Nginx + PHP-FPM 还是 Apache
  • 具体报错信息

我可以直接帮你定位问题。

0 踩