No update-alternatives in AlmaLinux 8 for PHP

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?

Don’t use “alternatives”, but the “module” command instead.

See My PHP development Workstation - Remi's RPM repository - Blog

Notice, these SCL are not official AlmaLinux build, so better to ask in the right place

From redhat documentation.

so you must use remi repo to have this on almalinux 8

How would I set PHP 5.6 as the default instead of PHP 7.4? PHP 7.4 is from AppStream and PHP 5.6 is from REMI.

The official repository (AppStream) provides

  • base packages of PHP 7.4 and 8.0 to be installed as default/single version

Remi’s repository provides

  • base packages of PHP 7.2 to 8.2 to be installed as default/single version
  • software collections of PHP 5.6 to 8.2 to be installed as multiple versions beside the default one

See the Wizard for proper configuration / installation

and as explained there, the php56-syspaths package allows you to force the default version (system-wide for all users), but this means you have to only use software collections.

BTW, I usually recommend setting the newer version as default, so have an officially maintained version, and use SCL for the older version and for legacy apps.

Please, remind that all versions <= 7.4 are retired and not maintained by the PHP project (even if the available packages have security fixes backported). See the supported versions page.