Topic: Pecl-ssh2 with PHP 8.2.5

After upgrading from PHP 8.2.2 to the latest PHP 8.2.5 repo on Amazon Linux 2 - I get an issue with ssh2.so, with php82-php-pecl-ssh2 installed

[ec2-user@ip-... ~]$ php -i | grep "ssh"
Warning: PHP Startup: Unable to load dynamic library 'ssh2.so' (tried: /opt/remi/php82/root/usr/lib64/php/modules/ssh2.so (/opt/remi/php82/root/usr/lib64/php/modules/ssh2.so: undefined symbol: libssh2_userauth_publickey_frommemory), /opt/remi/php82/root/usr/lib64/php/modules/ssh2.so.so (/opt/remi/php82/root/usr/lib64/php/modules/ssh2.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
/etc/opt/remi/php82/php.d/40-ssh2.ini
libSSH Version => libssh2/1.4.3

The ssh2.so file exists:

[ec2-user@ip-... ~]$ ls /opt/remi/php82/root/usr/lib64/php/modules/ssh2.so -la
-rwxr-xr-x 1 root root 89408 Apr 21 05:36 /opt/remi/php82/root/usr/lib64/php/modules/ssh2.so

If I revert that individual file to an earlier version, then PHP runs without a warning
Using the version that shipped with PHP 8.2.2 (ignore the file date - that's just today's date):

[ec2-user@ip-... ~]$ ls /opt/remi/php82/root/usr/lib64/php/modules/ssh2.so -la
-rwxr-xr-x 1 root root 89296 May  2 08:22 /opt/remi/php82/root/usr/lib64/php/modules/ssh2.so

[ec2-user@ip-... ~]$ php -v
PHP 8.2.5 (cli) (built: Apr 11 2023 16:16:23) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.5, Copyright (c), by Zend Technologies

[ec2-user@ip-... ~]$ php -i | grep "ssh"
/etc/opt/remi/php82/php.d/40-ssh2.ini
Registered PHP Streams => ht_tps, ftps, compress.zlib, php, file, glob, data, ht_tp, ftp, compress.bzip2, phar, zip, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp
libSSH Version => libssh2/1.4.3
ssh2
libssh2 version => 1.10.0
banner => SSH-2.0-libssh2_1.10.0

I've experienced the same issue on 4 servers I've put this on so far.
Please can you confirm if you can reproduce the same issue, and if it's perhaps resolved in 8.2.6?

Thanks!  (I put underscores in ht_tp because the forum code was complaining about having links in...)

Re: Pecl-ssh2 with PHP 8.2.5

Sorry cannot reproduce.. (on CentOS 7.7)

$ rpm -q php82-php-cli php82-php-pecl-ssh2
php82-php-cli-8.2.5-1.el7.remi.x86_64
php82-php-pecl-ssh2-1.4-1.el7.remi.x86_64

$ ldd /opt/remi/php82/root/usr/lib64/php/modules/ssh2.so
    libssh2.so.1 => /opt/remi/libssh2/lib64/libssh2.so.1 (0x00007fde0453c000)
         ...

$ rpm -qf /opt/remi/libssh2/lib64/libssh2.so.1
remi-libssh2-1.10.0-1.el7.remi.x86_64
Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: Pecl-ssh2 with PHP 8.2.5

BTW notice that EL-7 is old, terribly old, close to its end of life in ~1year

To run modern features (such as PHP 8.2) I heartily recommend using a modern distro (EL-8 or EL-9)

More, amzn2 is a kind of Frankenstein distribution, initially based on EL-7 but now really outdated (compared to the latest 7.7)

Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: Pecl-ssh2 with PHP 8.2.5

Can reproduce on amzn2

Workaround:

yum update -y --noplugins libssh2

which should install version 1.8.0 from "remi-safe"

Using a simple Dockerfile

FROM amazonlinux:2

RUN yum update -y

# Import archive signing keys and update packages
RUN rpm --import https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7 && \
    rpm --import https://rpms.remirepo.net/RPM-GPG-KEY-remi && \
    yum install -y yum-utils && \
    yum update -y

RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
                   https://rpms.remirepo.net/enterprise/remi-release-7.rpm && \
    yum install -y --setopt=tsflags=nodocs --noplugins \
        php82-php-cli php82-php-ldap php82-php-pecl-ssh2 && \
    yum clean all

RUN yum update -y --noplugins libssh2

RUN php82 --modules && php82 --version

ENTRYPOINT ["php82"]
CMD ["-a"]

Everything seems OK

# docker run -ti foo --ri ssh2

ssh2

SSH2 support => enabled
extension version => 1.4
libssh2 version => 1.10.0
banner => SSH-2.0-libssh2_1.10.0
Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: Pecl-ssh2 with PHP 8.2.5

An alternative workaround is to disable curl ext, or ensure ssh2 is loaded before

# docker run -ti foo -n -d extension=curl -d extension=ssh2 --ri ssh2

Warning: PHP Startup: Unable to load dynamic library 'ssh2' (tried: /opt/remi/php82/root/usr/lib64/php/modules/ssh2 (/opt/remi/php82/root/usr/lib64/php/modules/ssh2: cannot open shared object file: No such file or directory), /opt/remi/php82/root/usr/lib64/php/modules/ssh2.so (/opt/remi/php82/root/usr/lib64/php/modules/ssh2.so: undefined symbol: libssh2_userauth_publickey_frommemory)) in Unknown on line 0
Extension 'ssh2' not present.

# docker run -ti foo -n -d extension=ssh2 -d extension=curl --ri ssh2

ssh2

SSH2 support => enabled
extension version => 1.4
libssh2 version => 1.10.0
banner => SSH-2.0-libssh2_1.10.0

So, a simple workaround:

mv /etc/opt/remi/php82/php.d/40-ssh2.ini /etc/opt/remi/php82/php.d/19-ssh2.ini

P.S. I may consider a fix in the package... but as this only affects amz2 users... and don't want to break other users installation...

Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: Pecl-ssh2 with PHP 8.2.5

So, after a small thinking, worth to be fixed

New build (php-pecl-ssh2-1.4-2) have new name for its configuration file (19-ssh2.ini)

Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi