Installing the SSH2 PHP extension on CentOS is actually pretty simple. Although it isn’t available as a straight yum install, it boils down to a few short steps.
Firstly, we’re going to install the dependencies:
yum install gcc php-devel php-pear libssh2 libssh2-devel
These will allow us to build the SSH2 extension using pecl.
pecl install -f ssh2
After running that command, it should stop at a line like:
.. ........done: 22,740 bytes 5 source files, building running: phpize Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 libssh2 prefix? [autodetect] :
All you have to do is hit Enter and it should detect the proper path. Once the install is completed, you just have to tell PHP to load the extension when it boots.
touch /etc/php.d/ssh2.ini echo extension=ssh2.so > /etc/php.d/ssh2.ini
Now restart your webserver and test to see if the changes took effect.
/etc/init.d/httpd restart php -m | grep ssh2
You should get a line returned with ‘ssh2′.
« Editing your DNS in Linux/CentOS WordPress: PHP Fatal error: Call to undefined function wp_dashboard_setup() »

This is good to know. I don’t know much about it. Thanks for important and interesting information. I learned a lot.
at this…
# libssh2 prefix? [autodetect] :
I get…
“configure: error: cannot find OpenSSL or Libgcrypt, try –with-libssl-prefix=PATH or –with-libgcrypt-prefix=PATH”
Hi LeCook,
Did you follow the first step? If you have libssh2 installed in a non-standard directory, this will cause the install to fail.
Also, do you have openssl installed? Try yum install openssl.
Cheers
Thanks for this…. it worked with Centos 6 as well
One note, your shell commands to add to php.d dir is:
cat echo extension=ssh2.so > /etc/php.d/ssh2.ini
cat shouldn’t be in that line!
@Weave, thanks for that! Let’s blame that on some sort of weird copy+paste and fat finger combination..
Thank you this is really good information.
I hope you can help me. I installed the dependencies like you said but after I hit enter to [autodetect] a ways down in the process it reads:
configure: error: The required libssh2 library was not found….
ERROR `/tmp/pear/temp/ssh2/configure –with-ssh2′ failed
Not knowing much about server stuff – what do I do?
Hi Freddy,
This usually happens when you don’t install the ‘libssh2-devel’ package. Can you paste the output of ‘yum info libssh2-devel’?
What repository are you geting libssh2 and libssh2-devel from? They’re not in the default or Atomic.
Nevermind, I found them at http://repoforge.org/
have this issue:
1) unable to load ssh2:
[root@s ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@s ~]# php -m | grep ssh2
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/module s/ssh2.so’ – /usr/lib64/php/modules/ssh2.so: cannot open shared object file: No such file or directory in Unknown on line 0
[root@s ~]# yum install openssl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Package openssl-0.9.8e-20.el5_7.1.0.1.centos.x86_64 already installed and latest version
Package openssl-0.9.8e-20.el5_7.1.0.1.centos.i686 already installed and latest v ersion
Nothing to do
[root@s ~]# cat echo extension=ssh2.so > /etc/php.d/ssh2.ini
cat: echo: No such file or directory
cat: extension=ssh2.so: No such file or directory
[root@s ~]# yum info libssh2-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Error: No matching Packages to list
i hope to get some fix soon.. please email me solution as well if possible.
@icode: Make sure that you have the EPEL repo setup and enabled. Check it out here http://fedoraproject.org/wiki/About_EPEL
Hello buddy ,
My version PHP 5.3.6-13ubuntu3.3 … for that job i run the cmd “apt – get install lib ssh2-1-dev lib ssh-php” is there any wrong with that cmd instead of using this “yum install gcc php-devel php-pear libssh2 libssh2-devel ” but i could see the ssh2 in putty
Thanks,
Arun
@Arun
Installation in Ubuntu should be as simple as ‘sudo apt-get install libssh2-1-dev libssh2-php’. Once you’ve done that, skip the rest of the steps until:
/etc/init.d/httpd restart
php -m | grep ssh2
You’ll want to do
/etc/init.d/apache2 restart
php -m | grep ssh2
Thanks for the instructions, that’s really helpful. I am having one issue and was wondering if anyone had come across a solution fo this before:
After installing the libssh and ssh2.so files and restarting the server, I get the following error (same as iCode above):
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/ssh2.so’ – libssh2.so.1: cannot open shared object file: No such file or directory in Unknown on line 0
Tearing my hair out trying to resolve that issue.
Thanks!
Thanks! Great job
Jason, did you get that figured out? Seems as though libssh2 didn’t install. Can you paste the output of ‘yum install libssh2′?