Hello everyone . I’m facing an issue where composer is using a PHP version /usr/bin/php. Which does not always match the required version (in my case php8.1 instead of php8.2 which set as the main for the USER).
php -v
PHP 8.2.28 (cli) (built: Mar 13 2025 18:13:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.28, Copyright (c) Zend Technologies
with Zend OPcache v8.2.28, Copyright (c), by Zend Technologies
composer -V
Composer version 2.9.1 2025-11-13 16:10:38
PHP version 8.1.32 (/usr/bin/php8.1)
ls /usr/bin -l | grep php
lrwxrwxrwx 1 root root 21 Apr 12 2023 php → /etc/alternatives/php
-rwxr-xr-x 1 root root 4475056 Dec 24 2024 php5.6
-rwxr-xr-x 1 root root 4536520 Dec 24 2024 php7.0
-rwxr-xr-x 1 root root 4689080 Dec 24 2024 php7.1
-rwxr-xr-x 1 root root 5071224 Dec 24 2024 php7.2
-rwxr-xr-x 1 root root 4842584 Dec 24 2024 php7.3
-rwxr-xr-x 1 root root 4813912 May 9 2025 php7.4
-rwxr-xr-x 1 root root 5002576 Mar 13 2025 php8.0
-rwxr-xr-x 1 root root 5576200 Mar 13 2025 php8.1
-rwxr-xr-x 1 root root 5695272 Mar 13 2025 php8.2
-rwxr-xr-x 1 root root 5792208 May 9 2025 php8.3
-rwxr-xr-x 1 root root 6021712 May 9 2025 php8.4
update-alternatives --config php
There are 11 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/php8.4 84 auto mode
1 /usr/bin/php5.6 56 manual mode
2 /usr/bin/php7.0 70 manual mode
3 /usr/bin/php7.1 71 manual mode
4 /usr/bin/php7.2 72 manual mode
5 /usr/bin/php7.3 73 manual mode
6 /usr/bin/php7.4 74 manual mode
7 /usr/bin/php8.0 80 manual mode
* 8 /usr/bin/php8.1 81 manual mode
9 /usr/bin/php8.2 82 manual mode
10 /usr/bin/php8.3 83 manual mode
11 /usr/bin/php8.4 84 manual mode
My solution is to change the alias in .bash_aliases
from:
alias composer=“/home/USER/.composer/composer”
to:
alias composer=“php /home/USER /.composer/composer”
How correct is this approach?
And is it possible to make changes to the /usr/local/hestia/bin/v-add-user-composer file to make it out of the box?
diff ./v-add-user-composer ./v-add-user-composer.bak
< echo "alias composer=php /home/"$user"/.composer/composer" >> /home/$user/.bash_aliases
---
> echo "alias composer=/home/"$user"/.composer/composer" >> /home/$user/.bash_aliases