You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Drupal 9升级PHP 7.4至8后报错,求排查方向指引

Drupal PHP 7.4升级至8后异常排查方向

报错信息

Additional uncaught exception thrown while handling exception.
Original
ReflectionException: Class "Drupal\Core\EventSubscriber\ExceptionTestSiteSubscriber" does not exist in ReflectionClass->__construct() (line 30 of /home/sailbudd/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php).

ReflectionClass->__construct() (Line: 30)
Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass->process() (Line: 94)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() (Line: 762)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 1322)
Drupal\Core\DrupalKernel->compileContainer() (Line: 926)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 20)
Drupal\Core\Installer\InstallerKernel->initializeContainer() (Line: 476)
Drupal\Core\DrupalKernel->boot() (Line: 426)
install_begin_request() (Line: 116)
install_drupal() (Line: 48)
Additional
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "theme.manager". in Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() (line 1030 of /home/sailbudd/vendor/symfony/dependency-injection/ContainerBuilder.php).

Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() (Line: 600)
Symfony\Component\DependencyInjection\ContainerBuilder->doGet() (Line: 558)
Symfony\Component\DependencyInjection\ContainerBuilder->get() (Line: 649)
Drupal::theme() (Line: 22)
_drupal_maintenance_theme() (Line: 506)
drupal_maintenance_theme() (Line: 1025)
install_display_output() (Line: 271)
_drupal_log_error() (Line: 365)
_drupal_exception_handler()

排查入手方向

  • 确认Drupal版本与PHP 8的兼容性:Drupal 8系列最高仅支持PHP 7.4,PHP 8需要Drupal 9.1及以上版本。如果当前是Drupal 8,直接升级PHP到8会出现核心类缺失(比如ExceptionTestSiteSubscriber是Drupal 9新增的类),需先把Drupal升级到9.x或10.x版本。
  • 校验核心文件完整性:检查core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php文件是否存在,若缺失,重新下载对应Drupal版本的核心包覆盖core目录(注意备份自定义配置和文件)。
  • 强制清理缓存:手动删除sites/default/files/php/目录下的所有缓存文件,避免旧的服务定义残留导致容器编译失败。若能执行Drush命令,可运行drush cr。
  • 更新Composer依赖:执行composer check-platform-reqs检查依赖是否适配PHP 8,再运行composer update更新所有依赖包,确保Symfony等组件版本支持PHP 8。
  • 排查自定义代码兼容性:临时禁用所有自定义模块和主题,仅保留核心模块,若网站恢复正常,再逐个启用自定义代码排查问题——部分旧代码可能使用了PHP 7.4的语法(比如匿名函数的旧写法、类型声明差异)或依赖不兼容的库。
  • 检查PHP扩展:确认PHP 8已安装Drupal所需的全部扩展(如gd、mbstring、xml、json等),可通过php -m命令查看已启用的扩展,对比Drupal官方要求。

内容的提问来源于stack exchange,提问作者Allan Lavridsen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 00:50:16