CentOS 6.4 - Install SSH2 extension for PHP

    Install the necessary packages before you can build/install ssh2 extension
    yum install gcc php-devel php-pear libssh2 libssh2-devel make
    Install the extension, (hit enter for autodetect when it prompts you)
    pecl install -f ssh2
    Once the install is completed, you just have to tell PHP to load the extension when it boots.
    echo extension=ssh2.so > /etc/php.d/ssh2.ini
    Restart your webserver and test to see if the changes took effect.
    service httpd restart
    You can check it installed with the following command
    php -m | grep ssh2



  1. When I ran "pecl install -f ssh2" it gave me following error:
    "PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 3200 bytes) in /usr/share/pear/pearcmd.php on line 66

    Should I change the value of pearcmd.php?

    1. I doesnt got this i installed all and succs :)

    2. Thank you. It's good to know that I probably didn't leave something out.

  2. I have not come across this problem. Did you manage to find out what was wrong? Has anyone else had the same problem? If so please leave a comment.

  3. Good tutorial!!!! Tout a marché comme sur des roulettes.

  4. Worked for me Centos 6.4 x64. Many Thanks

  5. When I run "pecl install -f ssh2", I've got this message:

    No releases available for package "pecl.php.net/ssh2"
    install failed

    Do you know what could be happening?

  6. worked on centos 6.4 x64! Thanx!

  7. This line (touch /etc/php.d/ssh2.ini) gives the error "touch: cannot touch `/etc/php.d/ssh2.ini': No such file or directory" on centOS 6.4 x64 for me. However, if I skip that and check it (php -m | grep ssh2) it comes back with "ssh2".

    1. That touch command was redundant anyways as the echo command should create the file if it does not exist already and because there is a single > instead of two >>, then it replaces the file. I don't know why you got that error message. Are you not running as a subuser instead of root? Glad it's working anyway.

  8. Hi,

    When i try to test if its installed successfully by

    php -m | grep ssh2

    I get

    PHP Syntax Error: Unexpected '(' in /etc/php.d/ssh2.ini on line 37

    What could be reason for this? Thanks for looking into this.

  9. i use centos 7, it's work. thank for the guide.

  10. Thanks!!!!!!!!!!!!I need it!!!!!!!!!!!!
    Centos 6.7.Work!

  11. This helped me a lot on Centos 6.8 Thanks!

  12. This helped me on Centos 6.8 Thanks!

  13. Where can i do find phpize????
    [root@servac etc]# pecl install -f ssh2
    downloading ssh2-0.13.tgz ...
    Starting to download ssh2-0.13.tgz (28,984 bytes)
    .........done: 28,984 bytes
    6 source files, building
    running: phpize
    sh: phpize: command not found
    ERROR: `phpize' failed

    [root@servac etc]# yum install php-devel
    Loaded plugins: product-id, security, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    Setting up Install Process
    puppetlabs-deps | 951 B 00:00
    puppetlabs-products | 951 B 00:00
    rhel | 1.1 kB 00:00
    rhel-source | 2.6 kB 00:00
    rhel-source-beta | 1.3 kB 00:00
    rhel-updates | 951 B 00:00
    No package php-devel available.
    Error: Nothing to do

    1. Hey Дмитрий Ковергин,
      Sorry for the late response, but I thought the phpize command would have been installed when you ran installed the php-devel package with "yum install gcc php-devel php-pear". I assume this because the PHP documentation states:

      "If the system is missing the phpize command, and precompiled packages (like RPM's) are used, be sure to also install the appropriate devel version of the PHP package as they often include the phpize command along with the appropriate header files to build PHP and its extensions."
      - source: http://php.net/manual/en/install.pecl.phpize.php

  14. When I enter pecl install -f ssh2 I get "-bash: pecl: command not found"

    1. Sounds to me like pecl was not installed. What is your output if you run the first command again:

      yum install gcc php-devel php-pear libssh2 libssh2-devel make

      THis stack overflow post on troubles installing pecl in centos may be helpful: https://stackoverflow.com/questions/19517095/struggling-to-install-php-pecl-on-centos