homebrewpecllibssh2php-7.3ssh2

Install ssh2 extension having homebrew and php 7.3


I am facing the following error while trying to install ssh2 extension with pecl:

17 warnings and 3 errors generated.
make: *** [ssh2_fopen_wrappers.lo] Error 1
ERROR: `make' failed

Here is what I've done:

brew install php
brew install libssh2
pecl install ssh2-1.1.2

That installed php 7.3.3, libssh2 1.8.0 and failed to install ssh2-1.1.2.
Does anyone have a solution for the problem? Thank you!

Related links:
https://github.com/docker-library/php/issues/767
Install PECL SSH2 extension for PHP


Solution

  • My original answer: SSH2 for PHP7 MacOS?

    I finally found a solution on MacOS Mohave. I have PHP 7.3 installed by Homebrew:

    brew install php
    brew install libssh2
    

    Install development version of ssh2 pecl extension from the latest sources:

    cd ~/Downloads
    git clone https://github.com/php/pecl-networking-ssh2.git
    cd pecl-networking-ssh2
    phpize
    ./configure
    make
    make install
    

    Enable extension in php.ini. You can use TextEdit:

    open -e /usr/local/etc/php/7.3/php.ini
    

    Add extension="ssh2.so" to the beginning of the file and save.

    Test the result:

    php -i | grep 'libssh2 version'
    

    You should see

    libssh2 version => 1.10.0
    

    -- EDIT for Apple silicon (M1)

    Homebrew uses different path on Apple silicon machines and ./configure command fails with error: "checking for ssh2 files in default path... not found". I resolved this with setting custom path:

    ./configure --with-ssh2=/opt/homebrew/opt/libssh2