Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active July 5, 2023 09:18
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save magnetikonline/48ce1d1dca53b44666ba9332bc41c698 to your computer and use it in GitHub Desktop.
Save magnetikonline/48ce1d1dca53b44666ba9332bc41c698 to your computer and use it in GitHub Desktop.
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
Copy link

THANKS!

@jasomdotnet
Copy link

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
Copy link
Author

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
Copy link

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
Copy link

sergioPerez-e commented Aug 3, 2018

Jawira's comment worked for me. Thanks

@tomsisk
Copy link

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

@ahsanndevops
Copy link

i just found the solution just follow the wget steps when compline after
run the followign commands

export PHP_AUTOCONF=/usr/bin/autoconf
export PHP_AUTOHEADER=/usr/bin/autoheader
phpize
you need to run this command for your php version 
./configure --with-php-config=/usr/bin/php-config7.1
make
sudo make install

this will install ssh2 and yes edit you php.ini file to enable extension
to verify run commad
php -m | grep ssh2
output
ssh2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment