Drush Drupal 9

  1. Drush Version Drupal 9
  2. Drush Update Drupal 9
  3. Drush 10 Drupal 9
  4. Drush Drupal 9 Episode

My local site works fine but I can't get Drush 9 to 'see' my Drupal 8 site. The aliases seem to have been created and added to the drush/sites folder and running drush site:alias does show them. However running drush status shows my Drupal root as /app. My Drupal root is /app/docroot. My alias files do have this as their root (for local). Basic Idea Drush 9 provides a new command drush site:alias-convert which can convert Drush 8 style site aliases over to the Drush 9 yaml site alias style. This will create a one time export of the site aliases currently existing at amazee.io and save them within /app/drush/sites which then are used when running a command like drush sa. Drush is a command line shell and Unix scripting interface for Drupal. Drush core ships with lots of useful commands for interacting with code like modules/themes/profiles. Similarly, it runs update.php, executes SQL queries and DB migrations, and misc utilities like run cron or clear cache. Setup and install Drupal 9 with composer and drush 3 minute read The first stable release of Drupal 9 will be in June 2020, but a few days ago the core team released the first beta. This is a good time to start testing Drupal 9, so you'll be prepared when the stable. Drush is a command-line interface for Drupal that provides a wide set of utilities for administering and maintaining your site. Drush commands require a settings.php file, and it's a best practice to have one. Drupal 8 sites come with a bundled settings.php file out of the box. Drupal 6 and 7 sites do not contain a settings.php file; however, you can simply copy the sites/default/default.

Unfortunately Drush 9 does not provide the possibility to inject dynamic Site Aliases like Drush 8 did. We are working with the Drush team to implement this again. In the meantime we have a workaround that allows you to use Drush 9 with amazee.io.

Basic Idea

Drush 9 provides a new command drush site:alias-convert which can convert Drush 8 style site aliases over to the Drush 9 yaml site alias style. This will create a one time export of the site aliases currently existing at amazee.io and save them within /app/drush/sites which then are used when running a command like drush sa.

Preparation

In order to be able to use drush site:alias-convert you need to do the following:

  • rename the aliases.drushrc.php inside the drush folder to amazeeio.aliases.drushrc.php

Generate Site aliases

Now you can run the converting process:

  • drush site:alias-convert

It's a good practice to commit the resulting yaml files into your git repo, so your fellow developers don't need to do the same all the time.

Use Site Aliases

In Drush 9 all site aliases are prefixed with a group, in our case this is amazeeio. You can show all site aliases with their prefix via:

and to use them: drush @amazeeio.master ssh

Drupal

Update Site Aliases

If a new environment in amazee.io has been created, you can just run drush site:alias-convert to update the site aliases file.

Composer is a great tool for Drupal and in general PHP developers, but in some cases, it might take some effort to accomplish what you want. I tried to install Drupal 9 (dev version) and Drush 10 today and here's what I had to do to make it work.

I'm using Docker4Drupal for my local environment, so the first step was to configure a new project according to the documentation. After that, I just cloned Drupal 9 using GIT and executed composer install. Starting with Drupal 8.8, we have the template projects provided directly by Drupal core so we don't have to use drupal-composer/drupal-project anymore.

Now the fun part. To install Drush 10 in theory you just have to execute:

But if you do that you will see the following error:

Drupal 9 and Drush 10 Composer error

Drush Version Drupal 9

That looks scary!

Fortunately, fixing it is easy. This is happening because of symfony/var-dumper component. Drupal 9 has the following constraint:

while Drush 10 has this one:

Running composer install after you clone Drupal core will install version v5.0.0 of symfony/var-dumper. That's not good because Drush is not supporting that version.

Drupal

The fix is to find the common ground and add the following line to the composer.json file:

Version 4.x is supported by both Drupal 9 and Drush 10, so you will now be able to install the latest version of Drush. After adding this line first downgrade var-dumper and then install Drush:

Drush Update Drupal 9

Yay!

Drupal 9 and Drush 10 Composer success

Note: This will probably be fixed soon by Drush using the same versions of symfony/var-dumper as Drupal, but let this blog post be of educational value.

Drush 10 Drupal 9

***

Drush Drupal 9 Episode

You can also read my blog post on how to make your site Drupal 9 ready.

Goran Nikolovski is a creator, speaker, open-source contributor, web developer specialized in Drupal and DevOps enthusiast. He is the founder of this website and he enjoys sharing his knowledge and experiences.