0

I run the command update-alternatives --config php and nothing shows up. I checked for the binaries and they are executables in the /usr/bin folder. Installed PHP versions are 7.4 from the AppStream repository and PHP 5.6 from the REMI repository.

ll /usr/bin/php*
-rwxr-xr-x. 1 root root 6376328 Oct 11 01:34 /usr/bin/php
lrwxrwxrwx  1 root root      32 Feb 15 21:31 /usr/bin/php56 -> /opt/remi/php56/root/usr/bin/php
lrwxrwxrwx  1 root root      36 Feb 15 21:31 /usr/bin/php56-cgi -> /opt/remi/php56/root/usr/bin/php-cgi
lrwxrwxrwx  1 root root      33 Aug 11  2021 /usr/bin/php56-pear -> /opt/remi/php56/root/usr/bin/pear
lrwxrwxrwx  1 root root      38 Feb 15 21:31 /usr/bin/php56-phar -> /opt/remi/php56/root/usr/bin/phar.phar
-rwxr-xr-x. 1 root root 6375784 Oct 11 01:34 /usr/bin/php-cgi
-rwxr-xr-x. 1 root root    4741 Oct 11 01:34 /usr/bin/phpize

With Java, I noticed they are symlinks to alternatives.

[root@alma8-webapps-dev alternatives]# ll /usr/bin/java*
lrwxrwxrwx. 1 root root 22 Feb 10 00:39 /usr/bin/java -> /etc/alternatives/java
lrwxrwxrwx. 1 root root 23 Feb 10 00:39 /usr/bin/javac -> /etc/alternatives/javac
lrwxrwxrwx. 1 root root 25 Feb 10 00:39 /usr/bin/javadoc -> /etc/alternatives/javadoc
lrwxrwxrwx. 1 root root 23 Feb 10 00:39 /usr/bin/javap -> /etc/alternatives/javap

One option is to rename the PHP 7.4 files, so I'll rename them as follows:

mv /usr/bin/php /usr/bin/php74 
mv /usr/bin/php-cgi /usr/bin/php74-cgi

After that, I create new alternatives:

alternatives --install /usr/bin/php php /usr/bin/php74 1
alternatives --install /usr/bin/php php /usr/bin/php56 2
alternatives --install /usr/bin/php-cgi php-cgi /usr/bin/php74-cgi 1
alternatives --install /usr/bin/php-cgi php-cgi /usr/bin/php56-cgi 2

The entries are now in alternatives:

update-alternatives --config php

There are 2 programs which provide 'php'.

  Selection    Command
-----------------------------------------------
   1           /usr/bin/php74
*+ 2           /usr/bin/php56

Enter to keep the current selection[+], or type selection number:

It has created symlinks to alternatives

 ll /usr/bin/php*
lrwxrwxrwx  1 root root      21 Feb 17 19:56 /usr/bin/php -> /etc/alternatives/php
lrwxrwxrwx  1 root root      32 Feb 15 21:31 /usr/bin/php56 -> /opt/remi/php56/root/usr/bin/php
lrwxrwxrwx  1 root root      36 Feb 15 21:31 /usr/bin/php56-cgi -> /opt/remi/php56/root/usr/bin/php-cgi
lrwxrwxrwx  1 root root      33 Aug 11  2021 /usr/bin/php56-pear -> /opt/remi/php56/root/usr/bin/pear
lrwxrwxrwx  1 root root      38 Feb 15 21:31 /usr/bin/php56-phar -> /opt/remi/php56/root/usr/bin/phar.phar
-rwxr-xr-x. 1 root root 6376328 Oct 11 01:34 /usr/bin/php74
-rwxr-xr-x. 1 root root 6375784 Oct 11 01:34 /usr/bin/php74-cgi
lrwxrwxrwx  1 root root      25 Feb 17 19:59 /usr/bin/php-cgi -> /etc/alternatives/php-cgi
-rwxr-xr-x. 1 root root    4741 Oct 11 01:34 /usr/bin/phpize

I tested updating PHP and it says PHP is no longer installed.

dnf update php
Last metadata expiration check: 0:28:58 ago on Fri 17 Feb 2023 07:41:07 PM AEDT.
Package php available, but not installed.
No match for argument: php
Error: No packages marked for upgrade.

How would I get alternatives to work with multiple versions of PHP and still be able to perform updates?

1 Answer 1

0

Duplicate of https://almalinux.discourse.group/t/no-update-alternatives-in-almalinux-8-for-php/2115/2

Already answer there

Use module command instead of alternatives

Example

$ module load php74
$ php -v
PHP 7.4.33 (cli) (built: Feb 14 2023 08:29:51) ( NTS )
$ module unload php74
$ module load php82
$ php -v
PHP 8.2.3 (cli) (built: Feb 14 2023 01:06:39) (NTS gcc x86_64)
$ module unload php82
$ php -v
PHP 8.1.16 (cli) (built: Feb 14 2023 18:59:41) (NTS gcc x86_64)

alternatives is permanent and system-wide (all users)

module is for current session, so much more flexible

Package php available, but not installed.

As dnf says, not installed, you probably need to update php-cli / php56-php-cli, or using the joker

# dnf update php\*

But as cherry-picking updates is a very bad practice, better to run a simple

# dnf update

In all cases, this update will break the manually set alternatives.

1
  • How would I set PHP 5.6 as the default instead of PHP 7.4?
    – supmethods
    Feb 18, 2023 at 7:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .