Cron job to maintain nextcloud

But that doesn’t help at all in this context. Then you can just as easily use php (without specifying the version). That’s what this query does: it asks which version is linked via the generic link /usr/bin/php.
It may well be that the web server is using a socket from a completely different PHP version. And since the script - in addition to the php-cli calls for the occ and updater.phar processes, also restarts the fpm service which is not addressed via a link but has to be called directly with the version, that is why you need to detect which socket from which php version is connected to which web server.
Detecting that is not as mundane as simply using:

  • php -v

or asking php directly in php:

  • php -r 'echo implode(."", array_slice(explode(."", PHP_VERSION), 0, 2));'

dpkg helper scripts can give you more information. List all installed php versions with:

  • phpquery -V

If that one shows you more than one version, then you must use other mechanisms to detect the used php Version.
That’s why it’s completely okay if the php version is defined in a variable if you don’t feel like writing 10 lines of code to detect it in all possible situations. :wink:

You can see exactly how that is done for all eventualities, including cases where the connection completely goes beyond the normal php, apache2 and or nginx configuration routines, in the php-updater script when calling

  • php-updater --list-installed

That lists exactly which sockets are listening, which modules are loaded and which socket is connected to which web server.
Here an example output:

  ==============================================================================
  actual PHP related packages installed and managed by dpkg
 X   Package                Version                                       Status
  ------------------------------------------------------------------------------
SAPI libapache2-mod-php8.1  8.1.27-1+ubuntu22.04.1+deb.sury.org+1           im
     \apache2handler /usr/lib/apache2/modules/libphp8.1.so <<INACTIVE
   - newrelic-php5          10.17.0.7                                       ia
     \included modules: newrelic-20151012 newrelic-20160303 newrelic-20170718
       newrelic-20180731 newrelic-20190902 newrelic-20200930 newrelic-20210902
       newrelic-20220829 newrelic-20230831
   - newrelic-php5-common   10.17.0.7                                       im
SAPI php8.1-cli             8.1.27-1+ubuntu22.04.1+deb.sury.org+1           im
     \php binary /usr/bin/php8.1 <<INACTIVE not linked
   - php8.1-common          8.1.27-1+ubuntu22.04.1+deb.sury.org+1           ia
     \included modules: calendar ctype exif ffi fileinfo ftp gettext iconv pdo
       phar posix shmop sockets sysvmsg sysvsem sysvshm tokenizer
SAPI php8.1-fpm             8.1.27-1+ubuntu22.04.1+deb.sury.org+1           im
     \listening on unix socket /run/php/php8.1-fpm.sock <<NOT CONNECTED
   - php8.1-opcache         8.1.27-1+ubuntu22.04.1+deb.sury.org+1           ia
     \included module: opcache
   - php8.1-readline        8.1.27-1+ubuntu22.04.1+deb.sury.org+1           ia
     \included module: readline
   - php8.2-apcu            5.1.23-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: apcu
   - php8.2-bcmath          8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: bcmath
   - php8.2-bz2             8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: bz2
SAPI php8.2-cli             8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \php binary /usr/bin/php8.2 <ACTIVE> linked to generic /usr/bin/php
   - php8.2-common          8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included modules: calendar ctype exif ffi fileinfo ftp gettext iconv pdo
       phar posix shmop sockets sysvmsg sysvsem sysvshm tokenizer
   - php8.2-curl            8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: curl
   - php8.2-dev             8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
SAPI php8.2-fpm             8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \listening on unix socket /run/php/php8.2-fpm.sock <CONNECTED> apache2
   - php8.2-gd              8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: gd
   - php8.2-gmp             8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: gmp
   - php8.2-igbinary        3.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: igbinary
   - php8.2-imagick         3.7.0-4+ubuntu22.04.1+deb.sury.org+2            im
     \included module: imagick
   - php8.2-intl            8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: intl
   - php8.2-mbstring        8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: mbstring
   - php8.2-mysql           8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included modules: mysqli mysqlnd pdo_mysql
   - php8.2-opcache         8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: opcache
SAPI php8.2-phpdbg          8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \phpdbg binary /usr/bin/phpdbg8.2 <ACTIVE> linked to generic /usr/bin/phpdbg
   - php8.2-readline        8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: readline
   - php8.2-redis           6.0.2-1+ubuntu22.04.1+deb.sury.org+1            im
     \included module: redis
   - php8.2-xml             8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included modules: dom simplexml xml xmlreader xmlwriter xsl
   - php8.2-zip             8.2.15-1+ubuntu22.04.1+deb.sury.org+1           im
     \included module: zip
   - php8.2-zmq             1.1.3-24+ubuntu22.04.1+deb.sury.org+2           im
     \included module: zmq
   - php-common             2:94+ubuntu22.04.1+deb.sury.org+2               ia
   - php-getallheaders      3.0.3-2                                         ia
   - php-guzzlehttp-psr7    1.8.3-1                                         im
   - php-pear               1:1.10.12+submodules+notgz+20210212-1ubuntu3    im
   - php-psr-http-message   1.0.1-2                                         ia
   - pkg-php-tools          1.42build1                                      ia
  ------------------------------------------------------------------------------
  actual PHP extension NOT installed and managed by dpkg
  ------------------------------------------------------------------------------
   - php8.2
     \module installed by admin: lua
  ------------------------------------------------------------------------------
  Status: - First letter (Desired Action):    - Second letter (Package Status):
            u=Unknown - i=Install - h=Hold      a=Automatic - m=Manual
  ------------------------------------------------------------------------------

You can see here, that there is an apache2handler php module for php8.1 which is not loaded and there are two listening fpm sockets but only one of them (8.2) is connected.
At the same time, this listing shows, that the /usr/bin/php is as well linked to the version 8.2 but that is not allways the case.

Do you see the dificulties now?


ernolf

2 Likes