SSH2 for PHP7 MacOS?

10,445

Solution 1

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://git.php.net/repository/pecl/networking/ssh2.git
cd 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

You should see

libssh2 version => 1.9.0

Solution 2

I managed to install php-ssh2 on MacOS High Sierra.

First I had to install libssh2, in order for PECL to compile the extension.

I used brew, however most likely libssh2 is available from mac ports also.

brew install libssh2

and then

pecl install ssh2-1.1.2

I have the Xcode command line tools (already) installed - which I assume was needed to compile the extension.

Solution 3

Try this:

pecl install ssh2-1.1.2

You can see available versions for ssh2 HERE

For those using alpine linux, make sure to add libssh2-dev first:

apk --update add libssh2-dev

Solution 4

On macOS Big Sur:

brew install libssh2
pecl install ssh2-1.2
Share:
10,445
Oman
Author by

Oman

Updated on July 21, 2022

Comments

  • Oman
    Oman almost 2 years

    When trying to use

    ssh2_sftp($this->con);
    

    PHP 7.1.7 thinks Im looking for a function in the class. After some reading, I found that SSH2 needs to be installed from PECL ( http://php.net/manual/en/wrappers.ssh2.php )

    When I went to do that, I got the following error:

    pecl/ssh2 requires PHP (version >= 4.0.0, version <= 6.0.0), installed version is 7.1.7
    No valid packages found
    install failed
    

    Anyone have any ideas on how to get this to run on MacOs 10.13.3 (17D47) with PHP 7.1.7? Thanks in advance!

  • mcgregor94086
    mcgregor94086 almost 5 years
    I tried this on a Mac running Mojave, and I got this error on "pecl install ssh2-1.1.2": No releases available for package "pecl.php.net/ssh2" install failed
  • Peter Knut
    Peter Knut over 4 years
    I tried on Mohave. Instalelled libssh2 1.9.0 without any problems. Than pecl installation failed with 17 warnings and 3 errors. It looks like incompatibility between libssh2 and pecl extension.
  • Collegeman
    Collegeman over 4 years
    This is the one that works for me! Thank you so much for posting this answer.
  • guice
    guice over 4 years
    +1 on this. It'll install ssh2 version 1.8.0. Thanks! You just unblocked our company's php7.3 update. :)
  • Haseeb Zulfiqar
    Haseeb Zulfiqar over 4 years
    any luck so far?
  • Erik Pöhler
    Erik Pöhler over 4 years
    worked for me. libssh2 was pulled in v1.9.0.1 from brew but pecl install only worked with ssh2-1.2
  • Blake Frederick
    Blake Frederick about 4 years
    This worked for me on macOS Catalina (10.15.2). Slight modification - I did pecl install ssh2-1.2.
  • Thomas
    Thomas about 2 years
    the new location for ssh2 (march 2022) is github.com/php/pecl-networking-ssh2.git