4

When trying to install the extension ssh2 via pecl, I encounter the below error messages. I was using a docker container based on php:7.3.2-fpm

Steps to reproduce:

  • Install PHP 7.3.2
  • Install the packages libssh2-1-dev and libssh2-1
  • Try to install the ssh2 extension via pecl install ssh2-1.1.2

So how can I successfully install the ssh2 extension?

...

/tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c: In function 'php_ssh2_fopen_wrapper_tunnel':
/tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c:1265:42: error: invalid operands to binary == (have 'zend_string {aka struct _zend_string}' and 'int')
  if (resource->path && resource->path[0] == '/') {
                        ~~~~~~~~~~~~~~~~~ ^~
/tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c:1268:8: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
   host = resource->path + 1;
        ^
Makefile:196: recipe for target 'ssh2_fopen_wrappers.lo' failed
make: *** [ssh2_fopen_wrappers.lo] Error 1
ERROR: `make' failed

I found this question unanswered and put on hold on superusers when I first googled for it. I think its more suited here.

Marco
  • 550
  • 2
  • 6
  • 22

2 Answers2

3

Theres an existing report on bugs.php.net, where user goldorakhong commented to compile it from source.

Using a docker file this can be done so:

RUN cd /tmp \
    && git clone https://git.php.net/repository/pecl/networking/ssh2.git \
    && cd /tmp/ssh2/ \
    && .travis/build.sh \
    && docker-php-ext-enable ssh2

If your not using docker you'll need to substitute docker-php-ext-enable to register the variable somehow else.

Marco
  • 550
  • 2
  • 6
  • 22
  • This is very opinionated but I recommend [phpseclib](https://github.com/phpseclib/phpseclib) over ssh2. It can be installed via composer. No need for PEAR or compiling. Also ssh2 constantly gave me segfaults and worse when using the `ssh2.sftp://`-wrapper. – Marco Jul 31 '19 at 14:37
  • Why does the build.sh script in the .travis directory CREATE A NEW USER and give it ssh access on the server? That does not seem like a good idea, nor does it seem necessary. Is there any reasonable explanation for this? – JohnGalt Apr 13 '20 at 23:02
0

Windows 2008 R2 64 bit

Wampserver 3.1.9 64 bit

PHP 7.3.12

1 - Download php_ssh2.dll and php_ssh2.pdb from https://windows.php.net/downloads/pecl/releases/ssh2/

2 - Select 9/18/2019 11:50 AM 1.2

3 - Select 9/18/2019 10:45 AM 438049 php_ssh2-1.2-7.3-ts-vc15-x64.zip

4 - Unzip and copy php_ssh2.dll and php_ssh2.pdb into C:/wamp64/bin/php/php7.3.12/ext/

5 - In php.ini insert line: extension=php_ssh2.dll

6 - In wamp restart all services

toprawa
  • 43
  • 4