PHP confusion after upgrading Raspbian Bullseye

The automatic update from one to the next php-version is done by so called “dependency-packages” like ‘php ’ and other packages with names like php-{module} (without the version String) Those packages allways depend on the latest version (which is 8.3 at the moment) and can almost all safely be removed, what will give you back the control over your php-version. When you try to deinstall such a package, you will see if it is a dependency for one or more php8.2-* modules (like php-common which is allways needed). All other packages that don’t meet any dependencies can safely (and should) be removed.
A package as ‘php8.2 ’ is a so caled “meta-package” and can be removed as well.

Then you should only install the packages WITH version string (php8.2-{module} instead of php-{module}).

Then you should - as mentioned by @Dzrenner - do the update-alternatives, but not as in his suggestion only for the php linkgroup but for all php related linkgroups:

for linkgroup in $(ls /var/lib/dpkg/alternatives/ | grep -E "ph(ar|p)"); do sudo update-alternatives --config $linkgroup; done

And here is a little more information about PHP in general:

You should look, which php-sapi (sapi = Server API) you are working with.

These are the most important sapis:

Command Line Interface

  • cli
  • package - php<VER>-cli
  • description:
    cli is used by php scripts invoked from the command line. i.e. all processes that were explicitly NOT called by the web server (cron jobs, occ commands, etc.)

Apache2 module

  • apache2
  • package - libapache2-mod-php<VER>
  • description:
    the apache2 module is the default sapi for apache2. The downside is that it’s not particularly scalable and doesn’t support http2. libapache2-mod-php relies on the old but stable Multi-Processing Module (MPM) “mpm-prefork”.

Fast Process Manager

  • fpm
  • package - php<VER>-fpm
  • description:
    this is the default sapi used by nginx. On apache2 php-fpm relies on the more scalable threaded MPM “mpm-event”. Additionally it needs the apache2-modules “proxy_fcgi” and “setenvif”.

Every sapi has its own php.ini file: /etc/php/<VER>/<SAPI>/php.ini

If your webserver is apache2, you can find out the active mpm (Multi Processing Module) with this command call:

sudo apachectl -M 2>/dev/null | grep mpm

as explained above, the “mpm_event_module” means that apache2 speaks via fpm, while the “mpm_prefork_module” indicates that the apache2 module is used for the comunication between webserver and php.

  • the sapi used by apache 2 can also be found out with this command call:
sudo apachectl -tD DUMP_INCLUDES 2>/dev/null | grep -v sites | sed -n '/php.*conf/ s#.*/\([^/]*\)\.conf#\1#p'
Explanation taken from php-updater script:

Much luck,
ernolf

1 Like