So I have a class that I build that uses the ssh2 package in php. I have successfully set this up and used and tested this class on apache2 server. The server at work where this is going to be running is an instance of litespeed. I have scoured the web for a way to get ssh2 working with this litespeed server however I cannot for the life of me figure it out. I get ssh2_connect() function not found. If I go go /etc/php/... I can see that the ssh2.ini file exists. However I believe the active php instance is located /usr/local/lsws/lsphp74/7.4/etc/php/ where I do not see the ss2.ini located. Is there a way to get ssh2 installed in the directory that is being used by the server? If I run ssh2_connect at the command prompt, it works just fine as it is most likely using the /etc/php instance of php.
CodePudding user response:
You're correct, ssh2_connect()
is provided by a pecl extension. These are optional binary add-ons for php. I'd make a quick phpinfo();
page and add it to the litespeed server so you can see what modules are active and where the config files php is using are actually located on disk.
The install guide can walk you through installing this pecl extension. https://www.php.net/manual/en/ssh2.requirements.php
Another way to accomplish this is with a pure-php library that doesn't depend on special plug-ins. phpseclib fully implements the ssh protocol in pure php, taking advantage of libraries if they are present but it's able to function without them.
CodePudding user response:
since you didn't mention what exactly is your server env
I would assume it's either OpenLiteSpeed image , or CyberPanel image
first of all , compile libssh2
wget https://libssh2.org/download/libssh2-1.10.0.tar.gz
tar vxzf libssh2-1.10.0.tar.gz
cd libssh2-1.10.0
./configure
make
make install
then compile the PHP extension
mkdir /usr/local/lsws/lsphp74/tmp
pecl channel-update pecl.php.net
/usr/local/lsws/lsphp74/bin/pear config-set temp_dir "/usr/local/lsws/lsphp74/tmp"
/usr/local/lsws/lsphp74/bin/pecl install https://pecl.php.net/get/ssh2-1.3.1.tgz
echo "extension=ssh2.so" > /usr/local/lsws/lsphp74/etc/php/7.4/mods-available/50-ssh2.ini
and finally , restart lsphp process to load new module
touch /usr/local/lsws/admin/tmp/.lsphp_restart.txt
or
killall lsphp
then verify by phpinfo();
to make sure you see ssh2 loaded