Alternatives and multiple php's

Please check the following:

mario@fedora:~$ sudo update-alternatives --install /usr/bin/php  php /usr/bin/php74  90
mario@fedora:~$ sudo update-alternatives --install /usr/bin/php  php /usr/bin/php84  80


mario@fedora:~$ sudo update-alternatives --config php

There are 3 programs which provide 'php'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/bin/php
   2           /usr/bin/php84
   3           /usr/bin/php74

Enter to keep the current selection[+], or type selection number: 2
failed to link /usr/bin/php -> /etc/alternatives/php: /usr/bin/php exists and it is not a symlink

mario@fedora:~$ php -v
PHP 8.2.21 (cli) .... 

I am not sure how to understand and fix. Thanks.

sudo alternatives --remove-all php
sudo alternatives --install /usr/local/bin/php php /usr/bin/php74 70
sudo alternatives --install /usr/local/bin/php php /usr/bin/php84 80
sudo alternatives --install /usr/local/bin/php php /usr/bin/php 100
sudo alternatives --auto php
sudo alternatives --display php
1 Like

Thanks so much. Take care.

1 Like

Why do you want to use “alternatives”?
This seems a poor way

It is probably simpler to install the version you want as the “default” version (so as /usr/bin/php)

The “module” command allows to switch to another version and does not require any admin privileges

Using alternatives for the “php” command is not enough, you have other related commands (phar, phpize, php-config, pear, pecl…)

Using /usr/local/bin/php won’t work for packaged applications that use hardcoded path (/usr/bin/php)

3 Likes

On vacation. As soon as I am back, I’ll check your advise.
(Actually, I need php74 just to run an older version of Symfony3).
Thanks

Hi. I can’t manage to set alternatives. Please help me.

rsdev@fedora:/usr/bin$ sudo alternatives --config php

There are 3 programs which provide 'php'.

  Selection    Command
-----------------------------------------------
 + 1           /usr/bin/php74
   2           /usr/bin/php84
*  3           /usr/bin/php

Enter to keep the current selection[+], or type selection number: 1
rsdev@fedora:/usr/bin$ php -v
bash: /usr/bin/php: No such file or directory

I can’t understand what I am doing wrong…

rsdev@fedora:/usr/bin$ ls -l /etc/alternatives/php
lrwxrwxrwx. 1 root root 15 oct  5 16:54 /etc/alternatives/php -> /usr/bin/php8.1
rsdev@fedora:/usr/bin$ ls -l /usr/bin/php8.1
ls: cannot access '/usr/bin/php8.1': No such file or directory