Skip to content

Instantly share code, notes, and snippets.

Embed
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 https://github.com/php/pecl-networking-ssh2/archive/master.zip
$ unzip master.zip
$ cd pecl-networking-ssh2-master
$ phpize
$ ./configure
$ make

Extension will be available for use at ./modules/ssh2.so.

Reference

@yungtechboy1

This comment has been minimized.

Copy link

@yungtechboy1 yungtechboy1 commented Aug 20, 2016

THANKS!

@jasomdotnet

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 ssh2.so file in folder modules. Place it somewhere to path /usr/lib/php/20151012/ as a root and add this

extension=/usr/lib/php/20151012/ssh2.so

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

<?php
phpinfo();
?>

It should contains "ssh2" string.

@magnetikonline

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!

@jawira

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/ssh2.so /usr/lib/php/20151012/ssh2.so

  2. Then create an ini file /etc/php/7.0/mods-available/ssh2.ini with the following content:

    extension=ssh2.so
    
  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
    ...
    ssh2
    ...
    

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

@sergioPerez-e

This comment has been minimized.

Copy link

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

Jawira's comment worked for me. Thanks

@tomsisk

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