Question: I am using the official php docker image as base for my application container, so the Dockerfile starts like so: 

```
FROM php:5.6-fpm-jessie

```

Later in the file I would like to have something like that: 

```
 RUN apt-get update \
    && apt-get install -y libssh2-1-dev libssh2-1 \
    && docker-php-ext-install ssh2

```

But that tells me:

```
/usr/src/php/ext/ssh2 does not exist

```

So since that is a debian (yessie) based image, only the old php5 packages are available and php7 is installed by some tricky script in the [php:fpm dockerfile](https://stackoverflow.com/questions/46805787/docker-phpfpm-install-php-extensions) and it seams that all extensions are compiled within the used php executable.

How can I install more extensions in this scenario?

Answer: 
In case you are using PHP >=8.0 image:

```
FROM php:8.0.2-fpm

RUN apt-get install -y libssh2-1-dev libssh2-1 \
    && pecl install ssh2-1.3.1 \
    && docker-php-ext-enable ssh2

```
It looks like the pecl option isn't available for anything newer then PHP 6. In order to get it installed, I had to build from source. From `php:7.1.27-cli` I was able to get it setup with these commands - the `php:7.1.27-cli` image is based on debian stretch:

```sh
# install dependencies 
RUN apt-get update && apt-get install -y \
    ssh \
    libssh2-1 \
    libssh2-1-dev \
    wget \
    libssl-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Install ssh2 extension
RUN wget -O libssh2.tar.gz https://www.libssh2.org/download/libssh2-1.8.1.tar.gz \
    && wget -O ssh2.tgz https://pecl.php.net/get/ssh2-1.1.2.tgz \
    && mkdir libssh2 && tar vxzf libssh2.tar.gz -C libssh2 --strip-components 1 \
    && mkdir ssh2 && tar vxzf ssh2.tgz -C ssh2 --strip-components 1 \
    && cd libssh2 && ./configure \
    && make && make install \
    && cd ../ssh2 && phpize && ./configure --with-ssh2 \
    && make && make install \
    && echo "extension=ssh2.so" >> /usr/local/etc/php/conf.d/ssh2.ini \
    && cd ../ && rm -rf libssh2.tar.gz ssh2.tgz ssh2 libssh2

```