Drush 9 别名文件应该在 Drupal 8 中的什么位置?

2021-12-29 00:00:00 alias php drupal-8 drupal drush

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

I have tried some ways to create an alias for my local Drupal project, I'm referring to : https://www.drupal.org/node/1401522
https://www.drupal.org/project/drush/issues/831272
https://www.drupal.org/project/drush/issues/786766

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

I can connect by running this command :

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:wamp64inphpphp7.2.10php.exe
 PHP config       : C:wamp64inphpphp7.2.10php.ini
 PHP OS           : WINNT
 Drush script     : C:wamp64wwwexecutive-coatingsvendorindrush.phar
 Drush version    : 9.6.2
 Drush temp       : C:UserskAppDataLocalTemp
 Drush configs    : C:/Users/k/.drush/drush.yml
                    C:/wamp64/www/executive-coatings/vendor/drush/drush/drush.yml
 Install profile  : minimal
 Drupal root      : C:wamp64wwwexecutive-coatings
 Site path        : sites/default
 Files, Public    : sites/default/files
 Files, Temp      : /tmp

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

But when I try to use a drush alias it doesn't work. Here my alias file :

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

运行 drush @local status 返回 [preflight] 找不到别名 @local.

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

I think I put my alias file in the wrong directory, can you provide the correct path ?

推荐答案

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

Alias file location is not your only issue here, because you are running Drush 9.x. Here the major changes between Drush 8.x and Drush 9.x regarding aliases :

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

  • Site aliases are no longer PHP files but YAML files. Hopefully Drush 9.x comes with a command to convert your old drush 8 aliases :

drush site:alias-convert

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

  • The user alias locations used in Drush 8 (~/.drush/sites, /etc/drush/sites) are by default no longer parsed, but you can register any location where alias files may be placed in your ~/.drush/drush.yml configuration file. Setting the old Drush 8 paths can be done automatically by running :

    drush core:init
    

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

    It writes the following to ~/.drush/drush.yml :

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

    例如在您的情况下,可以在文件中完成为网站 executive-coatings 别名 ecc 定义一个本地环境(提供此位置已按上述方式注册)~/.drush/sites/ecc.site.yml.

    For example in your case, defining a local environment for the website executive-coatings aliased ecc may be done in the file (provided this location is registered as mentioned above) ~/.drush/sites/ecc.site.yml.

    您还可以在以下位置(在该网站的项目根目录下,使用 self 在文件命名中):

    You can also define environment aliases (eg. @dev, @preprod, etc.) for a given website at the following location (under the project root of that website, using self in the file naming) :

    <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

    相关文章