首页 > 解决方案 > Drush 9 别名文件应该位于 Drupal 8 中的哪个位置?

问题描述

我已经尝试了一些方法来为我的本地 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.

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

标签: phpdrupalaliasdrupal-8drush

解决方案


别名文件位置不是您唯一的问题,因为您正在运行 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
    

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

  • 您还可以在以下位置(在该网站的项目根目录下,在文件命名中使用self )为给定网站定义环境别名(例如,@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


推荐阅读