Run composer with different php version

If your default php is 7.2 for ex. but your site is with php7.4-fpm, how to use the same php7.4 when using composer for managing the modules?
How to have multiple php? https://www.digitalocean.com/community/tutorials/how-to-run-multiple-php...
How to use them?
Just in virtualhost config use as

<VirtualHost *:80>
...
        <FilesMatch \.php$>
            # Apache 2.4.10+ can proxy to unix socket
                SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
        </FilesMatch>
...
</VirtualHost>

So, on the topic "Run composer with different php version":

Append in ~/bashrc
alias composer_php74="/usr/bin/php7.4 /usr/local/bin/composer"

execute from ~
source .bashrc

test it:
composer_php74 -v

use from the project root as
composer_php74 require drupal/mymodule

For sure nobody denied you to run the equivalent
/usr/bin/php7.4 /usr/local/bin/composer require drupal/mymodule

Use what is convenient to you.

Cheers.

Category: