Intuition
I was recently working on a client site, and I got to the issue where the site will show “Page unavailable” upon login. And upon the suspicion of a mis-placed module or uncleared cache, I wanted to install drush to perform some drush commands.
I ran composer require drush/drush
which will install the most recent compatible drush on my current working directory, but then I got this error:
|
|
After some research, I found this issue could be potentially related to a version mis-match of the composer and the drupal 8 (reference: link), the composer in the project could be of version 1.XX, and the local instance is using version 2.XX …
Failed Attempt
I quickly went online and found this solution: link, that uses the following command to upgrade/downgrade composer:
|
|
But this one only updates the composer version globally, and it does not solve the issue of installing drush on the current working directory. (I am using MAMP as my web server, and as a result, I will need to update the version of the composer located at /Applications/MAMP/bin/php/composer
)
Working Solution
In order to upgrade the “correct” composer, I did the following:
First, getting one composer 1.10 version phar file from this site: link. Place it on some location you can found, here I am putting it at my MAMP directory
/Applications/MAMP/bin/php/composer.phar
.(Note: in order to run this file, you will either need to use box command to compile it (
box compile composer.php
), or use php as the interpreter to run it (php composer.php
), Since here we are only using it temporarily, we will use the shortcut of php: `php /Applications/MAMP/bin/php/composer.phar –version )Second, I will need to find the correct compatible version of drush via the official website, for my instance
drush/drush:10
Third, running the require command to install:
php /Applications/MAMP/bin/php/composer.phar require drush/drush:10
Lastly, (OPTIONAL) If the memory is not sufficient during the
composer install/update
you might see something ilke this:Fatal error: Allowed memory size of 1610612736 bytes exhausted
.In order to change the memory limit you will need to add a parameter
-d memory_limit=-1
, the command comes together looks like:php -d memory_limit=-1 /Applications/MAMP/bin/php/composer.phar require drush/drush:10
As a result you should see the downloaded instance of composer installing drush successfully: