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

References

26 comments:

  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?

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

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

      Delete
  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.

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

    ReplyDelete
  4. Worked for me Centos 6.4 x64. Many Thanks

    ReplyDelete
  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?

    ReplyDelete
  6. worked on centos 6.4 x64! Thanx!

    ReplyDelete
  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".

    ReplyDelete
    Replies
    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.

      Delete
  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.

    ReplyDelete
    Replies
    1. have you found a solution to your problem ?

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

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

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

    ReplyDelete
  12. This helped me on Centos 6.8 Thanks!

    ReplyDelete
  13. Thank you so much, successful on Centos 6.9

    ReplyDelete
  14. 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

    ReplyDelete
    Replies
    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

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

    ReplyDelete
    Replies
    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

      Delete
    2. This is what I get:

      Package gcc-4.4.7-18.el6.x86_64 already installed and latest version
      No package php-devel available.
      No package php-pear available.
      Package libssh2-1.4.2-2.el6_7.1.x86_64 already installed and latest version
      Package libssh2-devel-1.4.2-2.el6_7.1.x86_64 already installed and latest version
      Package 1:make-3.81-23.el6.x86_64 already installed and latest version

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

    ReplyDelete
  17. 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.

    ReplyDelete
  18. Thanks a lot!! I follow your instruction step by step , and successfully installed!!
    PS. I also modify php.ini

    ReplyDelete