phppecl

How to resolve module version mismatch for pecl extension?


I have php 8.0.30:

PHP 8.0.30 (cli) (built: Sep  2 2023 08:05:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies
    with Xdebug v3.4.1, Copyright (c) 2002-2025, by Derick Rethans

When loading extensions, it uses the path:

/usr/lib/php/20200930/

Now, I installed runkit7 via:

pecl install runkit7-4.0.0a6

Yet the runkit7.so file will be placed at:

/usr/lib/php/20230831/runkit7.so

Simply moving the runkit7.so file to the used directory won't work as there is a strong requirement for the versions to match:

PHP Warning:  PHP Startup: runkit7: Unable to initialize module
Module compiled with module API=20230831
PHP    compiled with module API=20200930
These options need to match
 in Unknown on line 0

How to install pecl extension for my module version?


I have different versions of php installed:

$ sudo update-alternatives --list php
/usr/bin/php7.4
/usr/bin/php8.0
/usr/bin/php8.1
/usr/bin/php8.2
/usr/bin/php8.3

I have https://ppa.launchpadcontent.net/ondrej/php/ubuntu/ in my sources.

The server has:

$ lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy

Solution

  • You have multiple PHP versions on your system and you created (compiled) the .so (shared object) of the runkit extension for a different PHP version then you wanted.

    As you could already demonstrate, the binaries are not necessarily compatible across PHP versions, and yours specifically not.

    You compiled it for module API=20230831, that is PHP 8.3 on your system:

    $ printf '%s\n' php8.{0..4} | xargs -IPHP sh -c \
        'PHP -i | grep -F "Extension Build" | sed "s/^/PHP: /"'
    
    php8.0: Zend Extension Build => API420200930,NTS  <------ your preferred
    php8.0: PHP Extension Build => API20200930,NTS    <--´    target version
    
    php8.1: Zend Extension Build => API420210902,NTS
    php8.1: PHP Extension Build => API20210902,NTS
    php8.2: Zend Extension Build => API420220829,NTS
    php8.2: PHP Extension Build => API20220829,NTS
    
    php8.3: Zend Extension Build => API420230831,NTS   <----- your actual
    php8.3: PHP Extension Build => API20230831,NTS     <--´   runkit.so
    
    php8.4: Zend Extension Build => API420240924,NTS
    php8.4: PHP Extension Build => API20240924,NTS
    

    You are using a Debian based Linux distribution, namely Ubuntu.

    Ondřej Surý is your package manager for the PHP packages, and he has been writing about PECL Installation in the oerdnj/deb.sury.org Wiki (github.com).

    Before you run any pecl command, you switch your PHP version to the version you want the PECL module to be installed for. Lets say we pick [php8.0]

    update-alternatives --set php /usr/bin/php8.0
    update-alternatives --set php-config /usr/bin/php-config8.0
    update-alternatives --set phpize /usr/bin/phpize8.0
    

    That is, before you use pecl(1) you must choose the right version from the Debian Alternatives System.

    The wikipage has more details.