phpbashubuntuoci8

How to build same php extension for multiple versions on the same server with Ubuntu?


I have a server with Ubuntu 22.04 that has multiple versions of PHP installed using ondrej:ppa. I need to add oci8 extension to all supported versions. This is the procedure that I have been using:

phpver='7.4'
builddir="/build$phpver"
instpath='/opt/oracle/instantclient_21_12'

[ "$phpver" = '7.4' ] && oci8version='oci8-2.2.0'
[ "$phpver" = '8.0' ] && oci8version='oci8-3.0.1'

update-alternatives --set php "/usr/bin/php${phpver}" && \
update-alternatives --set phpize "/usr/bin/phpize${phpver}" && \
update-alternatives --set php-config "/usr/bin/php-config${phpver}" && \
rm -f "/etc/php/${phpver}/mods-available/oci8.ini" && \
touch "/etc/php/${phpver}/mods-available/oci8.ini" && \
pear config-set php_ini "/etc/php/${phpver}/mods-available/oci8.ini" && \
mkdir -pv "$builddir" && \
pear config-set temp_dir "$builddir" && \
pecl install -f --configureoptions "with-oci8=\"instantclient,$instpath\"" "$oci8version" && \
phpenmod -v "${phpver}" oci8
pear config-set php_ini ''
pear config-set temp_dir ''
rm -rf "$builddir"

Executing this for one version of PHP everything is fine. When I try to execute for a different version of php the extension also builds fine but the extension for previously used version of php is deleted???

I am obviously doing something wrong here.


Solution

  • I think your issue here is that PECL creates a registry file of what it thinks is currently installed, so as soon as you switch to a different PHP version, that registry file is no longer appropriate. After each build step, remove the registry file that PECL just created, so that it doesn't use that existing file for the next step -- and I think you'll be good to go:

    rm /usr/share/php/.registry/.channel.pecl.php.net/oci8.reg
    

    Note this will show incorrect output for pecl list in the future. Alternatively, you can build the packages manually, without using the pecl install wrapper:

    pecl download oci8-3.3.0 # (or whatever version is appropriate for your PHP)
    tar xzf oci8-3.3.0.tgz
    cd oci8-3.3.0
    phpize
    ./configure --with-oci8=instantclient,/path/to/dir
    make
    mv modules/oci8.so $(php-config --extension-dir)
    chmod 644 $(php-config --extension-dir)/oci8.so # might need this
    

    And then you'd have to also manually adjust your php.ini to load the module.