Page 1 of 1

composer version not switching with PHP version

Posted: Wed Aug 31, 2022 12:11 am
by polera
I'm working on a PHP 5 app trying to upgrade it to PHP 8; this means I have to support both versions, the deprecated one for the existing live website, and the new one I'm converting.

However, when I switch PHP versions in MAMP Pro to PHP 5, it now seems to keep composer 2.4 (which I use for PHP 8, which requires composer 2.3+), when composer 2.2 is supposed to be used.

My MAMP PHP settings are Default version 5.6.40 or 8.1.1 using Mode Module (all hosts use the same PHP version) with checkmarked options "Activate command line shortcuts for the selected PHP version, pear, pecl et al" and "Also activate shortcut for Composer". I've found this to be the least amount of pain having worked with a dozen PHP apps from version 5.6 to 7.4 (especially where one required I use domain localhost), but now PHP 8 has too wide of a discrepancy with composer to PHP 5 to use the same version.

So anyway, I think I just need MAMP's composer shortcut to point to composer 2.2 for PHP 5, and composer 2.4 for PHP 8 (and preferably composer 2.3 for PHP 7). Ultimately I'd be OK with each repo having its own composer.phar, but it'd be nice for MAMP to just automatically handle it.

Output while on PHP 5 (some of it is weird):

me@my-mac app % which composer
composer: aliased to /Applications/MAMP/bin/php/composer
me@my-mac app % where composer
composer: aliased to /Applications/MAMP/bin/php/composer
/usr/local/bin/composer

Any way I run composer, I get this error on PHP 5:

me@my-mac app % composer self-update --2.2
Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 5.6.40, please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.

I have to switch to PHP 7, run self-update to 2.2, then switch back to PHP 5 and run the necessary commands.

However, switching back to PHP 8 breaks because MAMP's shortcut is pointing to composer 2.2! So I have to switch back to PHP 7, update composer to 2.4, then run the necessary PHP 8 composer commands. Super-frustrating! Too many hoops!

I have a workaround to add a composer.phar file to the PHP 5 repo, that I use while running PHP 5 to self-update it to 2.2, then make an alias of `php composer.phar`... I can do this with the PHP 8 repo as well... but then sometimes I forget to run the alias, and there could be something else that uses composer that will instead go through MAMP's alias which could be running an incompatible version...

Re: composer version not switching with PHP version

Posted: Tue Sep 27, 2022 6:28 pm
by polera
Nobody has any idea what I'm talking about?