在 CentOS 上调试 Laravel,通常可以从 日志、错误显示、调试工具、运行环境 几个方面入手。下面按实用程度给你一套完整方案。
php -v
composer -V
php artisan --version
确保:
mbstring, openssl, pdo, tokenizer 等).envAPP_ENV=local
APP_DEBUG=true
php artisan config:clear
php artisan cache:clear
tail -f storage/logs/laravel.log
常见错误:
Laravel 需要写权限:
chown -R nginx:nginx /var/www/laravel
chmod -R 755 storage bootstrap/cache
或(php-fpm 用户)
chown -R apache:apache storage bootstrap/cache
dd($user);
dump($request->all());
composer require laravel/telescope
php artisan telescope:install
php artisan migrate
访问:
http://your-domain/telescope
\DB::listen(function ($query) {
logger($query->sql, $query->bindings);
});
User::toSql();
tail -f /var/log/nginx/error.log
tail -f /var/log/php-fpm/error.log
yum install php-xdebug
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
配合 PHPStorm + Xdebug 可断点调试。
| 问题 | 解决 |
|---|---|
| 500 错误 | 看 laravel.log |
| 空白页 | APP_DEBUG=true |
| 权限拒绝 | chmod storage |
| SELinux 阻止 | setenforce 0 测试 |
如果你愿意,可以告诉我:
我可以帮你精准定位问题。