Score:1

Drupal root not found on multisite setup after upgrading Drush 10 to 11/12

br flag

This is a (25 sites) multisite setup running smoothly on Drupal 9.4 with Drush 10.x still. Upgrading to Drupal 10.1.x and Drush 11 or 12 however makes Drush unusable.

Dir layout as installed by drupal/core-recommended:

/var/www/projectroot/
├── composer.json
├── composer.lock
├── config
│   └── mysite.com
├── vendor
│   ├── asm89
│   │   └── stack-cors
│   ├── behat
│   │   ├── mink
│   │   ├── mink-browserkit-driver
│   │   └── mink-goutte-driver
│   ├── bin
│       └── drush
│   ├── bjeavons
│   │   └── drupal-finder
│   ├── drush
│   │   └── drush
│   │       ├── appveyor.yml
:   :       :
│   │       ├── drush
│   │       └── drush.bat
:   :
│   └── wikimedia
│       └── composer-merge-plugin
└── web
    ├── libraries
    ├── modules
    │   ├── contrib
    │   └── custom
    ├── profiles
    ├── robots.txt
    ├── sites
    │   ├── default
    │   └── mysite.com
    │       ├── files
    │       ├── services.yml
    │       └── settings.php
    ├── sites.php
    ├── themes
    │   └── mytheme
    ├── update.php
    └── web.config

: denotes items I think that are not relevant are left out. The vendor directory is actually much bigger:

$ find vendor | wc -l
41837

composer.json:

{
    "name": "myproject",
    "description": "myproject",
    "type": "project",
    "require": {
        "cweagans/composer-patches": "^1.7",
        "drupal/admin_feedback": "^2.2",
        "drupal/admin_toolbar": "*",
        "drupal/allowed_formats": "^1.3",
        "drupal/animated_gif": "^2.0",
        "drupal/asset_injector": "^2.7",
        "drupal/better_passwords": "2.x",
        "drupal/block_content_machine_name": "dev-3286263-automated-drupal-10 as 3.0.2",
        "drupal/bootstrap_barrio": "^5.1",
        "drupal/ckeditorheight": "^1.8",
        "drupal/config_split": "^2.0@RC",
        "drupal/config_update": "*",
        "drupal/cookies": "^1.0",
        "drupal/core": "10.1.*",
        "drupal/core-composer-scaffold": "10.1.*",
        "drupal/core-project-message": "10.1.*",
        "drupal/core-recommended": "10.1.*",
        "drupal/csv_importer": "^1.15",
        "drupal/draggableviews": "^1.2",
        "drupal/easy_breadcrumb": "^2.0",
        "drupal/editor_file": "*",
        "drupal/facets": "^2.0",
        "drupal/file_extractor": "^4",
        "drupal/fixed_block_content": "dev-3357439-ui-updating-to",
        "drupal/focal_point": "^2.0",
        "drupal/fontyourface": "^3.5",
        "drupal/glossify": "^2.0",
        "drupal/imce": "*",
        "drupal/libraries": "^4.0",
        "drupal/matomo": "^1.12",
        "drupal/menu_block": "*",
        "drupal/menu_breadcrumb": "*",
        "drupal/menu_item_role_access": "^2.0",
        "drupal/menu_trail_by_path": "*",
        "drupal/metatag": "^1.16",
        "drupal/migrate_plus": "^6.0",
        "drupal/migrate_process_url": "^2.0.x-dev",
        "drupal/migrate_tools": "^6.0",
        "drupal/override_node_options": "^2.6",
        "drupal/paragraphs": "^1.12",
        "drupal/paragraphs_edit": "^2.0",
        "drupal/pathauto": "^1.3",
        "drupal/permissions_by_term": "^3.1",
        "drupal/restui": "^1.17",
        "drupal/search_api": "^1.11",
        "drupal/simple_sitemap": "^4.1",
        "drupal/sitemap": "^2.0",
        "drupal/smart_trim": "*",
        "drupal/svg_image": "^1.14",
        "drupal/term_csv_export_import": "^4.0",
        "drupal/toc_js": "^2.1",
        "drupal/tome": "1.8.*",
        "drupal/unique_field_ajax": "^2.0",
        "drupal/user_current_paths": "^2.0",
        "drupal/user_redirect": "^1.0",
        "drupal/video_embed_field": "^2.0",
        "drupal/video_embed_wysiwyg": "^2.0",
        "drupal/views_ajax_history": "^1.2",
        "drupal/views_block_area": "^1.0",
        "drupal/viewsreference": "^2.0",
        "drupal/webform": "^6.0",
        "drush/drush": "^11",
        "http-interop/http-factory-guzzle": "^1.0",
        "guzzlehttp/guzzle": "^7.4",
        "phpmailer/phpmailer": "^6.0",
        "toc/toc": "*",
        "wikimedia/composer-merge-plugin": "^2.0"
    },
    "require-dev": {
        "behat/mink": "*",
        "behat/mink-goutte-driver": "*",
        "drupal/devel": "*",
        "mikey179/vfsstream": "~1.2",
        "phpunit/phpunit": "^9",
        "symfony/css-selector": "^4.4"
    },
    "authors": [
        {
            "name": "me",
            "email": "[email protected]"
        }
    ],
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8",
            "exclude": [ "drupal/search_api_meilisearch", "drupal/better_passwords", "drupal/block_content_machine_name", "drupal/fixed_block_content" ]
        },
        {
            "type": "package",
            "package": {
                "name": "toc/toc",
                "version": "v0.3.2",
                "type": "drupal-library",
                "dist": {
                    "url": "https://raw.githubusercontent.com/jgallen23/toc/greenkeeper/update-all/dist/toc.min.js",
                    "type": "file"
                }
            }
        },
        {
            "type": "git",
            "url": "git@mygitserver:search_api_meilisearch"
        },
        {
            "type": "git",
            "url": "https://git.drupalcode.org/issue/better_passwords-3296626.git"
        },
        {
            "type": "git",
            "url": "https://git.drupalcode.org/issue/block_content_machine_name-3286263.git"
        },
        {
            "type": "git",
            "url": "https://git.drupalcode.org/issue/fixed_block_content-3357439.git"
        }
    ],
    "minimum-stability": "dev",
    "extra": {
        "patches": {
            "drupal/core": {
                "Field options 'Rewrite results' and 'Link to the Content' applied together is not working as expected": "https://www.drupal.org/files/issues/2018-11-12/views_link_trim-2600456-22.patch",
                "Add file-mime formatter and make it output icons": "https://www.drupal.org/files/issues/2021-07-15/2907414-31.patch",
                "Large decimal number do not validate as they should": "https://www.drupal.org/files/issues/2022-07-26/2230909-269.patch",
                "Fix unnecessary multiple settings updates in AJAX calls": "https://www.drupal.org/files/issues/2021-05-12/2771361-42.patch",
                "Add a 'machine_name' widget for string field types with a UniqueField constraint": "https://www.drupal.org/files/issues/2023-05-17/drupal-10-1x-machine-name-widget-2685749-116.patch"
            },
            "drupal/toc_js": {
                "Disable showing the ToC as a default": "patches/toc_js_per_node_default_off.diff",
                "Fix umlaut and trailing special char conversion in ToC": "patches/toc_js_umlaut_and_trailing_char_fix.patch"
            },
            "drupal/metatag": {
                "Unset link rel: shortlink, edit-form, version-history and revision, and meta name: Generator, MobileOptimized, HandheldFriendly, viewport from <head> https://www.drupal.org/project/metatag/issues/2735195": "https://www.drupal.org/files/issues/2021-04-29/metatag-unset-2735195-59.patch"
            },
            "drupal/bootstrap_barrio": {
                "Add missing jquery.once dependency for affix.js (https://www.drupal.org/project/bootstrap_barrio/issues/3278329 and ../3366908) #9505-10": "https://www.drupal.org/files/issues/2023-06-14/3366908-2.patch"
            },
            "drupal/webform": {
                "Fix broken result export with drush": "https://www.drupal.org/files/issues/2023-01-26/3335851-4.patch"
            },
            "drupal/permissions_by_term": {
                "Fix content is not editable with 3.1.22": "https://git.drupalcode.org/project/permissions_by_term/-/merge_requests/20.patch"
            },
            "drupal/facets": {
                "Facets with AJAX not working": "https://www.drupal.org/files/issues/2023-02-07/facets-with-ajax-not-working-in-most-of-situations-3052574-174.patch"
            }
        },
        "drupal-scaffold": {
            "locations": {
                "web-root": "./web"
            }
        },
        "enable-patching": true,
        "installer-paths": {
            "web/core": [ "type:drupal-core" ],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "web/drush/contrib/{$name}": ["type:drupal-drush"],
            "web/themes/custom/{$name}": ["type:drupal-custom-theme"]
        },
        "merge-plugin": {
            "include": [
                "web/modules/contrib/webform/composer.libraries.json"
            ]
        }
    },
    "prefer-stable": true,
    "conflict": {
        "drupal/drupal": "*"
    },
    "config": {
        "sort-packages": true,
        "optimize-autoloader": true,
        "allow-plugins": {
            "composer/installers": true,
            "drupal/console-extend-plugin": true,
            "cweagans/composer-patches": true,
            "drupal/core-composer-scaffold": true,
            "drupal/core-project-message": true,
            "wikimedia/composer-merge-plugin": true,
            "php-http/discovery": true
        }
    }
}

As suggested in the comments, I reduced this to a minimum viable setup:

{
    "name": "myproject",
    "description": "myproject",
    "type": "project",
    "require": {
        "drupal/core": "*",
        "drupal/core-composer-scaffold": "*",
        "drupal/core-project-message": "*",
        "drupal/core-recommended": "*",
        "drush/drush": "*"
    },
    "authors": [
        {
            "name": "me",
            "email": "[email protected]"
        }
    ],
    "minimum-stability": "dev",
    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "./web"
            }
        },
        "enable-patching": true,
        "installer-paths": {
            "web/core": [ "type:drupal-core" ],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "web/drush/contrib/{$name}": ["type:drupal-drush"],
            "web/themes/custom/{$name}": ["type:drupal-custom-theme"]
        },
            "merge-plugin": {
            "include": [
                "web/modules/contrib/webform/composer.libraries.json"
            ]
        }
    },
    "prefer-stable": true,
    "conflict": {
        "drupal/drupal": "*"
    },
    "config": {
        "sort-packages": true,
        "optimize-autoloader": true,
        "allow-plugins": {
            "composer/installers": true,
            "drupal/console-extend-plugin": true,
            "drupal/core-composer-scaffold": true,
            "drupal/core-project-message": true,
            "php-http/discovery": true
        }
    }
}

After this, I ran composer update (as the recommended composer update "drupal/core-*" -W would not update drupal/core as it was still locked to 9.4.x). Still no joy.

On Drupal 9.4 and Drush 10.x, I was able to just use drush -l mysite.com when in /var/www/projectroot (or somewhere below, as well).

Now, no matter the CWD, I cannot for the life of me get drush to output meaningful stuff.

user@webserver:/var/www/projectroot/web $ ../vendor/drush/drush/drush --root=sites/mysite.com or user@webserver:/var/www/projectroot $ vendor/bin/drush --root=web/sites/mysite.com or any other parameter combination with -l or --url or using absolute paths does not yield anything meaningful. With drush 11 I get ! [NOTE] Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands.

With is really strange, as drush seems to find the root (last line):

user@webserver:/var/www/projectroot $ vendor/bin/drush st
PHP binary    : /usr/bin/php8.1
PHP config    : /etc/php/8.1/cli/php.ini
PHP OS        : Linux
PHP version   : 8.1.21
Drush script  : /var/www/projectroot/vendor/bin/drush
Drush version : 11.6.0
Drush temp    : /tmp
Drush configs : /var/www/projectroot/vendor/drush/drush/drush.yml
Drupal root   : /var/www/projectroot/web

Drush is installed via composer, as per the docs.

Drush 12 only gives me: The alias references a Drupal site that does not contain its own copy of Drush. Please add Drush to this site to use it. (Note the double blank after alias; I consider this a bug, the error message should be different when a variable is undefined). I can get similar output to Drush 11 if I use @none as an alias.

I don't need aliases and only want to use drush locally on this dev-server. Deployment has its own automatic framework.

Do I need a copy of drush in every multisite's sites/<sitename> dir? I know global drush is not supported anymore, I switched from a system-wide installed drush to one in my project dir installed via composer (like it is still now) back at Drupal 8 and consider this locally installed, but I may be wrong? If so, how?

Happy to provide more debug info if needed.

Thanks in advance for anyone taking a look at this!

id flag
There is almost nothing in the vendor directory.
leymannx avatar
ne flag
How exactly did you upgrade? Can you post your composer.json, too?
br flag
Updated the description to make clear the vendor dir is actually much bigger. Added composer.json. How did I upgrade? I changed all occurences of `9.4.*` in `drupal/*` packages to `10.1.*` and ran `composer update -W`, fixing all the incompatible packages one by one by either increasing the version or using patches where no stable versions are available, yet.
id flag
I don’t think this is the present issue but that isn’t how it’s done.
br flag
I can try with the recommended `composer update "drupal/core-*" -W"` as per the manual, but this gets really involved as I cannot require and update in one go, which I need as the core update blocks the other packages and vice versa. (I want all versions to be pinned). I have to remove all the packages and re-add them again this way. Did this, and will update the description. But as you said: It did not fix it.
br flag
I'm still stuck at this. Trying to further reduce the possible errors, I tried with a fresh setup and .. drumroll .. same error! Can anyone please try my minimum viable setup `composer.json` in my original post and issue `composer install` with it? It installs flawlessly, but drush is broken the same way it is when I upgrade my current install. There's either something inherently incompatible with my underlying OS/libs or my composer.json has an error I am unable to spot!
br flag
Progress! A fresh install as per the installation instructions (without my composer.json) works, so it has to be something in composer.json. Diff'ed them. `composer require "composer/installers": "^2.0"` makes drush work! Wouldn't this be very helpful to have as a dependency of core-recommended?
br flag
However, there's another issue: Issuing `drush -l mysite.org st` does not give the correct site path. It is always `sites/default`. (Even if I pass `--root`, strange.) This can be fixed by adding `$sites['mysite.org'] = 'mysite.org';` to `web/sites/sites.php`. Under Drupal 8 and 9, I had no `sites.php` as somehow the default of having directories like the corresponding URLs was enough. My question now is this: Is any of the issues I had a bug or are they features? How can we make sure other people find this out more quickly than (me) by debugging drush & friends?
Score:1
br flag

The issue was with composer.json needing another require statement for some version between 9.4 and 10.1, most likely >=10.x.

This fixed all mentioned drush issues regarding ! [NOTE] Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands. or The alias references a Drupal site that does not contain its own copy of Drush. Please add Drush to this site to use it.:

composer require "composer/installers" "^2.0"

Now, if you have a multisite setup that has worked on Drupal 8 and 9 without a web/sites/sites.php file (like me) and just using subdirectories that are called the same way as their URL, it seems you now have to explicitly define them in web/sites/sites.php (instantiate it using example.sites.php; just add $sites['mysite.org'] = 'mysite.org'; for every multisite).

Without that, my drush 12.1 + Drupal 10.1 were not able to correctly determine the site path (always set to sites/default when issuing drush -l mysite.org st).

Make sure your composer.json looks as similar as possible to the one you get with a fresh install as outlined in the official docs, currently at https://www.drupal.org/docs/develop/using-composer/starting-a-site-using-drupal-composer-project-templates. This helped me pinpoint the differences.

I consider this a bug in drush, there should be some check whether the needed packages are installed before failing in a way that does not give users a clue a package is missing.

The sites.php that is now needed should probably be part of the Drupal >=10.x release notes. If anyone knows how to disable the necessity for this, please chime in! This is an additional step in multisite creation/instantiation that is unnecessary imho, if there are no aliases/ports needed. It would be nice to have this as default again.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.