Problems Installing PHP SSH2 in order to use SFTP functions

adamcm

Registered
Oct 2, 2017
4
2
3
UK
cPanel Access Level
Root Administrator
I need to be able to write a script which connects to an SFTP server to retrieve a file.
My searching led me to the conclusion that I need the PHP SSH2 extension installed on my server to make this work.
I'm following the guide here:

and am stuck on point 3, which says to run the command:
Apache config:
/usr/local/cpanel/3rdparty/bin/pecl install ssh2
However, on doing so via terminal in WHM, I get the error message:

WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
pecl/ssh2 requires PHP (version >= 4.0.0, version <= 6.0.0), installed version is 7.3.30
No valid packages found

I am running Multi-PHP, and would like to install this extension on all versions that I have running - Can anyone help me with where to go next?

Thanks
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,519
1,028
313
cPanel Access Level
Root Administrator
Hey there! The output of the message indicates the problem - that specific pecl package is only available for PHP versions higher than 4 and lower than 6, which would mean you'd need to be using PHP 5.6 or older on cPanel in order to get that installed. The package is not available for newer versions of PHP, so it would be best to find a different piece of software that supports more modern installations.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,519
1,028
313
cPanel Access Level
Root Administrator
I see this has to be installed manually as a modern version isn't included from pecl directly. You can run this command to perform that work, just modifying the php## to work with your particular version. For example, this works with PHP 7.4:

Code:
/opt/cpanel/ea-php70/root/usr/bin/pecl install https://pecl.php.net/get/ssh2-1.2.tgz
Can you try that and let me know if that works?
 
  • Like
Reactions: thietbixe.com

adamcm

Registered
Oct 2, 2017
4
2
3
UK
cPanel Access Level
Root Administrator
Thank you, that worked and it installed successfully.
However, when attempting to use the ssh2_connect function, I receive the following error:
Error starting up SSH connection(-5): Unable to exchange encryption keys
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,519
1,028
313
cPanel Access Level
Root Administrator

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,519
1,028
313
cPanel Access Level
Root Administrator
Sure thing - you can run this on the command line through SSH or through the WHM >> Terminal:

Code:
rpm -qa | grep libssh
If you have automatic updates enabled on the system, it's likely you already have the latest available.