【问题标题】:Where Drush 9 aliases file should be located in Drupal 8?Drush 9 别名文件应该位于 Drupal 8 中的哪个位置?
【发布时间】:2019-08-30 10:59:55
【问题描述】:

我尝试了一些方法来为我的本地 Drupal 项目创建别名,我指的是: https://www.drupal.org/node/1401522
https://www.drupal.org/project/drush/issues/831272
https://www.drupal.org/project/drush/issues/786766

我可以通过运行这个命令来连接:

drush --root=C:/wamp64/www/executive-coatings --uri=http://localhost:81/executive-coatings status

输出:

 Drupal version   : 8.6.13
 Site URI         : http://localhost:81/executive-coatings
 DB driver        : mysql
 DB hostname      : localhost
 DB port          : 3306
 DB username      : root
 DB name          : dev_ecc_new
 Database         : Connected
 Drupal bootstrap : Successful
 Default theme    : ecc_front
 Admin theme      : adminimal_theme
 PHP binary       : C:\wamp64\bin\php\php7.2.10\php.exe
 PHP config       : C:\wamp64\bin\php\php7.2.10\php.ini
 PHP OS           : WINNT
 Drush script     : C:\wamp64\www\executive-coatings\vendor\bin\drush.phar
 Drush version    : 9.6.2
 Drush temp       : C:\Users\k\AppData\Local\Temp
 Drush configs    : C:/Users/k/.drush/drush.yml
                    C:/wamp64/www/executive-coatings/vendor/drush/drush/drush.yml
 Install profile  : minimal
 Drupal root      : C:\wamp64\www\executive-coatings
 Site path        : sites/default
 Files, Public    : sites/default/files
 Files, Temp      : /tmp

但是当我尝试使用 drush 别名时它不起作用。这是我的别名文件:

$aliases['local'] = array(
      'uri' => 'localhost:81/executive-coatings',
      'root' => 'C:/wamp64/www/executive-coatings',
  'path-aliases' => array(
    '%dump-dir' => '/tmp',
  ),
);

运行drush @local status 返回[preflight] The alias @local could not be found.

我想我的别名文件放错了目录,你能提供正确的路径吗?

【问题讨论】:

    标签: php drupal alias drupal-8 drush


    【解决方案1】:

    别名文件位置不是您唯一的问题,因为您运行的是 Drush 9.x。这里是 Drush 8.x 和 Drush 9.x 之间关于别名的主要变化:

    • 站点别名不再是 PHP 文件,而是 YAML 文件。希望 Drush 9.x 附带一个命令来转换您的旧 drush 8 别名:

      drush site:alias-convert
      
    • 默认情况下,Drush 8 中使用的用户别名位置(~/.drush/sites/etc/drush/sites)不再被解析,但您可以在 ~/.drush/drush.yml 配置文件中注册任何可能放置别名文件的位置。可以通过运行自动设置旧的 Drush 8 路径:

      drush core:init
      

      它将以下内容写入~/.drush/drush.yml

      drush:
        paths:
          alias-path:
            - '${env.home}/.drush/sites'
            - /etc/drush/sites
      

      例如,在您的情况下,可以在文件中为 executive-coatings 别名 ecc 网站定义 local 环境(提供该位置已如上所述注册)~/.drush/sites/ecc.site.yml

    • 您还可以在以下位置(在该网站的项目根目录下,使用 self 为给定网站定义 environment 别名(例如,@dev、@preprod 等) 在文件命名中):

      <DRUPAL_ROOT>/drush/sites/self.site.yml
      

    有用的链接:
    - https://github.com/drush-ops/drush/blob/master/examples/example.site.yml
    - https://github.com/consolidation/site-alias

    【讨论】:

    • 谢谢,我尝试使用 .yml 文件是正确的。
    • 正如你在我的问题中看到的那样,它显示`Drupal 版本:8.6.13`,但你提到我的drupal 版本是9,你有什么想法吗?
    • 我提到了你的 Drush 版本:Drush version : 9.6.2。这很令人困惑,因为 Drush 和 Drupal 版本控制不相关,请参阅docs.drush.org/en/master/install/#drupal-compatibility
    • 你也可以检查一下吗,stackoverflow.com/q/55610481/9246297
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    相关资源
    最近更新 更多