How to install “Secure Shell2 (SSH2)” PHP Extension
After much adoption of the SSH2 extension, the installation process has gotten a lot more simple, check it out:
yum install libssh2-devel pecl install ssh2-beta echo extension=ssh2.so >> /etc/php.ini
Now, you can restart your web server, and check a phpinfo page to verify the installation!
Installing the libssh2 and Secure Shell2 libraries is a real pain , 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!






