Php: how to install php-ssh2?

Created on 25 Dec 2018  路  8Comments  路  Source: docker-library/php

i try install php-ssh2 but get error
apt install php-ssh2

Reading package lists... Done
Building dependency tree
Reading state information... Done
Package php-ssh2 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php-ssh2' has no installation candidate

Most helpful comment

I can't install the extension directly. But it works when downloading them manually like this:

FROM php:7.4-apache
RUN apt-get update && \
    apt-get install -y gcc make libssh2-1-dev libssh2-1
RUN curl http://pecl.php.net/get/ssh2-1.2.tgz -o ssh2.tgz && \
    pecl install ssh2 ssh2.tgz && \
    docker-php-ext-enable ssh2 && \
    rm -rf ssh2.tgz
RUN echo '<?php phpinfo();' > /var/www/html/i.php

Navigating to http://127.0.0.1/i.php I see

SSH2 support    enabled
extension version   1.2
libssh2 version     1.8.0 

All 8 comments

From the Docs on the Docker Hub, you have a couple options: https://github.com/docker-library/docs/tree/b10ac9706270ca71044eb75ccf7158c5124a5a36/php#e-package-php-xxx-has-no-installation-candidate

Some clues:

  1. going to https://packages.debian.org/stretch/php-ssh2, we see the "Homepage" is https://pecl.php.net/package/ssh2, so pecl is the appropriate tool for installing this
  2. from that page:
    > ssh2 1.0 and above is PHP 7 only. To install a version that is PHP 5 compatible you can run 'pecl install ssh2-0.13'
  3. looking at dependencies of https://packages.debian.org/stretch/php-ssh2, you likely need libssh2-1-dev installed in order to compile

I was able to successfully install via the following:

FROM php:7.2-cli

RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends libssh2-1-dev; \
    pecl install ssh2-1.1.2; \
    docker-php-ext-enable ssh2

It's _also_ worth noting that when trying this against PHP 7.3, I get _heaps_ of errors, so PHP 7.3 likely isn't supported by the ssh2 module yet. https://bugs.php.net/bug.php?id=77265#1544266627 mentions that it's likely fixed in Git via http://git.php.net/?p=pecl/networking/ssh2.git;a=commit;h=a8835aab2c15e794fce13bd927295719e384ad2d (hopefully with a release pending soonish?)

OK thanks for supoort

# ssh2
RUN apt-get install -y \
    libssh2-1-dev

RUN cd /tmp && git clone https://git.php.net/repository/pecl/networking/ssh2.git && cd /tmp/ssh2 \
&& phpize && ./configure && make && make install \
&& echo "extension=ssh2.so" > /usr/local/etc/php/conf.d/ext-ssh2.ini \
&& rm -rf /tmp/ssh2

Doesn't work for me

Unable to locate package libssh2-1-dev

@yi-ge works for php5.4 too, thanks

I can't install the extension directly. But it works when downloading them manually like this:

FROM php:7.4-apache
RUN apt-get update && \
    apt-get install -y gcc make libssh2-1-dev libssh2-1
RUN curl http://pecl.php.net/get/ssh2-1.2.tgz -o ssh2.tgz && \
    pecl install ssh2 ssh2.tgz && \
    docker-php-ext-enable ssh2 && \
    rm -rf ssh2.tgz
RUN echo '<?php phpinfo();' > /var/www/html/i.php

Navigating to http://127.0.0.1/i.php I see

SSH2 support    enabled
extension version   1.2
libssh2 version     1.8.0 

@DMW007 's solution worked for, tried on php7.4-fpm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mbates picture mbates  路  3Comments

cmath10 picture cmath10  路  3Comments

cordoval picture cordoval  路  3Comments

2Kable picture 2Kable  路  3Comments

pukkancs picture pukkancs  路  3Comments