11

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!

Oman
  • 133
  • 1
  • 1
  • 11

5 Answers5

22

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
Peter Knut
  • 2,311
  • 20
  • 15
  • 1
    This is the one that works for me! Thank you so much for posting this answer. – Collegeman Aug 12 '19 at 15:53
  • +1 on this. It'll install ssh2 version 1.8.0. Thanks! You just unblocked our company's php7.3 update. :) – guice Sep 13 '19 at 23:12
  • 1
    the new location for ssh2 (march 2022) is https://github.com/php/pecl-networking-ssh2.git – Thomas Mar 23 '22 at 11:45
  • After successful ssh2 install I still have Error 32759. Unable to find the socket transport "ssh2.sftp" - did you forget to enable it when you configured PHP? – Eugene Kaurov Dec 02 '22 at 17:53
  • For me (PHP 7.4 & macOS Ventura M1) just `pecl install ssh2` and specifying _/opt/homebrew/opt/libssh2_ when asked, did the trick. I already had _libssh2_ installed with brew. – Juanmi Sosso May 29 '23 at 14:57
13

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.

crishoj
  • 5,660
  • 4
  • 32
  • 31
Nigel Atkinson
  • 660
  • 6
  • 11
5

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
lloiacono
  • 4,714
  • 2
  • 30
  • 46
2

On macOS Big Sur:

brew install libssh2
pecl install ssh2-1.2
Léo Benoist
  • 2,511
  • 1
  • 20
  • 18
0

On macOS Big Sur and with MacPorts and MAMP Pro:

sudo port install libssh2
cd ~/Downloads
git clone https://git.php.net/repository/pecl/networking/ssh2.git
cd ssh2

Then use an editor and edit ~/Downloads/ssh2/config.m4 around line 7 and change the search paths "/usr/local /usr" to "/usr/local /usr /opt/local" like this

if test "$PHP_SSH2" != "no"; then
    SEARCH_PATH="/usr/local /usr /opt/local"

save and go on:

phpize
./configure
make
make install

Then follow the steps in answer and regarding your PHP version…

slackero
  • 11
  • 2
  • 3