12 STEPS TO INSTALL LIBSSH2 FOR PHP7

After successfully using libssh2 with PHP5 from the last post, I need to use libssh2 with PHP7 too. Yet, to install libssh2 to be working with PHP7 is not as easy as in PHP5. From just running sudo apt-get install libssh2-php , you need another few more steps. The overall steps I followed was from this link. However, it’s not fully working for me, so the additional steps are needed.

Environment

Ubuntu 14.04.3 LTS x86_64 – Homestead (0.4.1)

Steps to Install libssh2

Install dependencies for PECL ssh2

sudo apt-get install libssh2-1-dev libssh2-1

sudo apt-get install libssh2-1-dev libssh2-1
Download PECL ssh2 fior PHP7
wget https://github.com/Sean-Der/pecl-networking-ssh2/archive/php7.zip

wget https://github.com/Sean-Der/pecl-networking-ssh2/archive/php7.zip
Unzip the file

unzip php7.zip

// you need unzip package, if you don’t have it yet, run this command
sudo apt-get install unzip

unzip php7.zip

// you need unzip package, if you don’t have it yet, run this command
sudo apt-get install unzip
Enter the directory

cd pecl-networking-ssh2-php7

cd pecl-networking-ssh2-php7
Locate phpize

//update index
sudo updatedb
locate phpize

//result
/usr/bin/phpize
/usr/bin/phpize7.0

//update index
sudo updatedb
locate phpize

//result
/usr/bin/phpize
/usr/bin/phpize7.0
Take the path of phpize and run in the directory

/usr/bin/phpize7.0

//result
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012

/usr/bin/phpize7.0

//result
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
Locate php-config

locate php-config

// result
/usr/bin/php-config
/usr/bin/php-config7.0

locate php-config

// result
/usr/bin/php-config
/usr/bin/php-config7.0
Check configuration and make sure you pass the path of php-config too

./configure –with-php-config=/usr/bin/php-config7.0

./configure –with-php-config=/usr/bin/php-config7.0
Then make and install

sudo make
sudo make install

sudo make
sudo make install
Add the extension into php.ini

extension=ssh2.so

extension=ssh2.so
Restart php7.0-fpm

sudo service php7.0-fpm restart

// your fpm might be named different, you can check the exact name by using
ls /etc/init.d | grep php

//result
php7.0-fpm

sudo service php7.0-fpm restart

// your fpm might be named different, you can check the exact name by using
ls /etc/init.d | grep php

//result
php7.0-fpm
Finally, test it!

 

 

References

  1. https://medium.com/php-7-tutorial/solution-how-to-compile-php7-with-ssh2-f23de4e9c319#.rqe01zrgx
  2. http://php.net/manual/en/install.pecl.phpize.php
  3. https://www.ikq.me/2016/01/12-steps-to-install-libssh2-for-php7/