Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Compile ssh2 bindings extension for PHP7.

Compile ssh2 bindings extension for PHP7

The current PHP ssh2 extension via PECL won't compile under PHP7.

Using a more recent version via PHP's GitHub we can make this work.

$ sudo apt-get install autoconf libssh2-1-dev
$ curl -LO
$ unzip
$ cd pecl-networking-ssh2-master
$ phpize
$ ./configure
$ make

Extension will be available for use at ./modules/



This comment has been minimized.

Copy link

@yungtechboy1 yungtechboy1 commented Aug 20, 2016



This comment has been minimized.

Copy link

@jasomdotnet jasomdotnet commented Sep 14, 2016

What is phpize? Is it command? I cannot install it on Ubuntu 16.04:

E: Unable to locate package phpize

Update: run command sudo apt-get install php-dev to obtain phpize command.

When you will finish steps above you will have file in folder modules. Place it somewhere to path /usr/lib/php/20151012/ as a root and add this


to the end of php.ini

sudo nano /etc/php/7.0/fpm/php.ini

and restart PHP7

sudo service php7.0-fpm restart

Create phpinfo.php somewhere on your server


It should contains "ssh2" string.


This comment has been minimized.

Copy link
Owner Author

@magnetikonline magnetikonline commented Oct 17, 2016

FYI - those steps above ☝️ are specific to Ubuntu/Debian packaging. But appreciate your comments, sure it will be helpful for some!


This comment has been minimized.

Copy link

@jawira jawira commented Feb 10, 2017

I have done the following to activate the extension on php7.0 CLI environment.

  1. First copy (or move) the compiled extension along the other php's extensions.
    $ sudo cp ./modules/ /usr/lib/php/20151012/

  2. Then create an ini file /etc/php/7.0/mods-available/ssh2.ini with the following content:
  3. Now create a symlink to activate the extension (this is what php5enmod does in php5 environements).
    $ sudo ln -s /etc/php/7.0/mods-available/ssh2.ini /etc/php/7.0/cli/conf.d/20-ssh2.ini

  4. That's it. You can check activated modules with the following command:

    $ php -m

Thanks a lot for the info, I needed ssh2 extension for a Phing project.


This comment has been minimized.

Copy link

@sergioPerez-e sergioPerez-e commented Aug 3, 2018

Jawira's comment worked for me. Thanks


This comment has been minimized.

Copy link

@tomsisk tomsisk commented Oct 19, 2018

This is really old, just putting a note here for future reference as you shouldn't use the master branch.

You can install the most recent version now, which supports PHP 7, by appending the version number:

$ pecl install ssh2-1.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment