Installing “Secure Shell2 (SSH2)” PHP Extension
Installing the libssh2 and Secure Shell2 libraries is a real pain in the ass, but I have to do it time to time, when I’m setting up new environments for the software I work on.
Before we begin, please note this is on a CentOS machine with the yum package manager install.
Note: Before you begin, make sure you have all the proper developer packages installed.
yum install gcc gcc-c++ autoconf automake (c compiler)
yum install php-devel (phpize)
Installing OpenSSL on CentOS 5.2
- Run the following two yum commands to install OpenSSL & it’s developer’s package. (libssh2 has dependencies on the OpenSSL developer package)
- yum install openssl
- yum install openssl-devel
Installing libssh2 libraries on CentOS 5.2
- Enter the following commands to download and install the latest libssh2 package.
- wget http://voxel.dl.sourceforge.net/sourceforge/libssh2/libssh2-0.18.tar.gz
- gunzip libssh2-0.18.tar.gz
- tar -xvf libssh2-0.18.tar.gz
- cd libssh2-0.18.tar.gz
- ./configure && make all install
Compiling libssh2 PHP Extension
- Use these commands to download and compile the libssh2 PHP module.
- wget http://pecl.php.net/get/ssh2-0.10.tgz
- gunzip ssh2-0.10.tgz
- tar -xvf ssh2-0.10.tgz
- cd ssh2-0.10.tgz
- phpize && ./configure –with-ssh2 && make « Generates ssh2.so, the compiled PHP extension.
- (Note: If you encounter a make: *** [ssh2.lo] Error 1 error, run Bill Pitz’s libssh2 patch.)
- cp ./modules/ssh2.so /usr/lib/php/modules/ssh2.so
- Open your PHP configuration file by typing vi /etc/php.ini and add extension=ssh2.so to the configuration, and save the file when you are complete.
Restart Web Server on CentOS 5.2
- service httpd restart
You should be all gravy, and your web server can now ssh out and perform remote tasks for you!
4 Responses to “Installing “Secure Shell2 (SSH2)” PHP Extension”
Leave a Reply

chook on February 2nd, 2009
thanks for pointing on libssh2 (yes, you are right, installing it is real pain …)
moi1504 on February 12th, 2009
Hi,
I have these errors when i try to do ssh2_connect
Warning: ssh2_connect() [function.ssh2-connect]: Error starting up SSH connection(-5): Unable to exchange encryption keys in /var/www/vhosts/commanderpileje.fr/httpdocs/interface/lib/client/sftp.php on line 161
Warning: ssh2_connect() [function.ssh2-connect]: Unable to connect to 62.193.246.149 in /var/www/vhosts/commanderpileje.fr/httpdocs/interface/lib/client/sftp.php on line 161
Any idea ?
Thanks
Duncan Robertson on February 17th, 2009
Nice one mate! Spent most of the day trying to get this to work. After reading your instructions - first time! Cheers!
inurinternet on February 21st, 2009
It looks like the ssh2 module can’t exchange keys with the remote server, how are you authing?