SSH2 for PHP7 MacOS?

Oman picture Oman · Apr 17, 2018 · Viewed 8.2k times · Source

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!

Answer

Peter Knut picture Peter Knut · Jul 31, 2019

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