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

本地部署Drupal9后执行Drush命令报错:Package 'drupal/core' is not installed

Drupal9迁移后Drush提示"drupal/core is not installed"问题排查

问题背景

在Windows10的Wampserver(PHP8.1.13)环境下,将现有Drupal9网站备份迁移至C:/wamp64/www/BDV-dev目录:

  • 已创建bdv_dev数据库,修改web/sites/default/settings.php配置数据库连接:
$databases['default']['default'] = array (
  'database' => 'bdv_dev',
  'username' => 'root',
  'password' => '',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'driver' => 'mysql',
    'collation' => 'utf8mb4_general_ci',
    'init_commands' => [
    'isolation_level' => 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
  ],
);
  • 虚拟主机配置正常,访问网站可完成安装流程;
  • 执行任何Drush命令(如drush sql-cli < dev.sql、drush status、drush cr)均触发错误:[preflight] Package "drupal/core" is not installed;
  • 已执行composer update -W更新依赖,切换至Xampp环境问题依旧;
  • 项目composer.json采用drupal/recommended-project模板,web根目录为web/,依赖包含drupal/core-recommended:^9.5和drush/drush:^11.6。

排查与解决步骤

1. 确保在项目根目录执行Drush

drupal/recommended-project的目录结构为项目根目录下包含web/(Drupal核心所在),必须在C:/wamp64/www/BDV-dev目录下执行Drush,而非web/子目录。

2. 使用项目本地Drush而非全局Drush

全局安装的Drush可能无法识别项目的依赖路径,优先使用项目本地的Drush:

# Windows命令
vendor\bin\drush status

3. 重新安装Composer依赖

可能存在依赖缓存或安装不完整的情况,执行以下步骤重置:

# Windows命令
rmdir /s vendor
del composer.lock
composer install

4. 手动指定Drupal根目录

如果Drush仍无法自动识别Drupal根目录,可通过--root参数指定:

vendor\bin\drush --root=web status

5. 验证PHP环境变量

确保Wampserver的PHP路径在系统环境变量的最顶部,避免其他环境的PHP版本干扰依赖加载:

  • 打开系统环境变量,在Path中优先添加C:\wamp64\bin\php\php8.1.13
  • 重启命令行窗口后执行php -v确认版本正确

6. 检查settings.php权限与完整性

确保web/sites/default/settings.php存在且权限正确(Windows下至少赋予读取权限),同时确认文件中未遗漏Drupal核心所需的配置项。

内容的提问来源于stack exchange,提问作者Clément BK

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 13:13:09