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: 
The easiest solution is to use `install-php-extensions`.
It's a script that can install the required system libraries automatically, on any Docker PHP image.

```dockerfile
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

RUN install-php-extensions ssh2

```

`install-php-extensions` can install a ton of other PHP extensions as well, not only `ssh2`: more details at <https://github.com/mlocati/docker-php-extension-installer>
I had some error on an other solutions
In my running container on [richarvey/nginx-php-fpm](https://hub.docker.com/r/richarvey/nginx-php-fpm) image worked with two command.

```
apk add --no-cache libssh2-dev autoconf build-base
pecl install https://pecl.php.net/get/ssh2-1.3.tgz
docker-php-ext-enable ssh2

```