19

I am trying to install this on a Windows+Apache machine. Documentation says that SSH2 requires the OpenSSL and libssh2 libraries. I have added this lines in my php.ini file:

extension=php_openssl.dll
extension=php_ssh2.dll

and restarted Apache but it still not working (Fatal error: Call to undefined function ssh2_connect()).

Can anyone explain me how to install this service?

BenMorel
  • 30,280
  • 40
  • 163
  • 285
LaYle
  • 191
  • 1
  • 1
  • 3

8 Answers8

29

Here's how I did it:

  1. Downloaded Win32 SSH2 PECL extension from this location (choose the appropriate version);

  2. Extracted the archive's content and:

    • placed php_ssh2.dll and php_ssh2.pdb files in the ext folder (e.g. C:\php\ext);
    • copied libssh2.dll file to C:\Windows\system32 and (if you got Win64) C:\Windows\SysWOW64 folder(s);
  3. Run the following command to register the DLL:

    C:\> regsvr32 libssh2.dll
    
  4. Restarted Apache.

Final note

If you got PHP x64, you have to lookup for the x64 version of the SSH2 library / DLLs. This site offers some Win64 compiled libraries for PHP, try here first.

Hope this helps.

Paolo Stefan
  • 9,358
  • 4
  • 43
  • 63
Alex B
  • 301
  • 3
  • 6
  • 1
    I am trying to setup this for command line use with Phing. Followed your instructions, `php -i` says `SSH2 support enabled`, however attempt to run Phing task ends up with windows message about PHP crashing. Any hints how to troubleshoot it? – Rarst May 29 '13 at 14:29
  • 1
    Got resolved by updating everything and anything in web stack to latest versions. Probably some DLL conflict or whatever. – Rarst May 29 '13 at 15:47
  • ...applied to systems with PHP 5.3.27 and PHP 5.4.15 versions. Worked flawlessly! – Milan Mar 21 '14 at 22:52
  • I'm using PHP 5.6 and I'm probably out of luck, there's no .dll to download and vc11 isn't compatible. – Christian Oct 10 '16 at 13:50
  • @Christian: I'm stuck needing this with PHP5.6 too...if you figure something out, PLEASE let us know :) – Metal450 Oct 11 '16 at 19:56
  • For PHP 7.1, I had to get from this location: http://pecl.php.net/package/ssh2/1.1.2/windows (the thread-safe version). I copied those files into my php/ext dir as described in this answer. Trying to run the regsvr32 didn't work for me, but I am not sure it was even necessary. I found a copy of libssh2.dll in the php dir already there. – Richard May 16 '19 at 19:14
9

If anyone is having trouble installing SSH2, here's how I did it:

1) Download SSH2 PECL library from PHP.net [choose the appropriate version].

2) Copy libssh2.dll to System32 [x86] or SysWOW64 [x64] folder.

3) Copy php_ssh2.dll and php_ssh2.pdb to php/ext folder.

4) Remove ';' from the ;extension=php_ssh2.dll line in php.ini. If this line is not on your php.ini, add it.

5) Restart Apache.

lucasbento
  • 105
  • 4
user2893097
  • 99
  • 1
  • 2
7
  1. Place php_ssh2.dll in ext folder
  2. Place libssh2.dll in php folder
  3. Restart IIS

that work for me

  • PHP 5.4.25 NTS + Windows Server 2012
chriz
  • 1,311
  • 2
  • 16
  • 31
MrTeChId
  • 71
  • 1
  • 1
  • 1
    I personally (on Windows 7) had to add these libs to `C:\Windows\SysWOW64` (on 32bit that is `C:\Windows\System32` ) – jave.web Feb 09 '16 at 20:12
5

If you are running xamp 3.2.1 and PHP 5.6.8, this could be helpful for you.

Do what alex b said, and download the package that corresponds dependindg your php version (and bits) from this page (link)

I've downloaded and replaced in C:\xampp\php\ext and it worked!

Hope this helps, regards.

Cristian B.
  • 176
  • 3
  • 10
4

libssh2 (deps): http://windows.php.net/downloads/php-sdk/deps/

php_ssh2 (ext): http://windows.php.net/downloads/pecl/releases/ssh2/0.12/

Versions prior to 5.5 has already the libssh2.dll (from the second link)

lodev09
  • 302
  • 1
  • 9
2

I have wamp with PHP 5.6.25/7.0.10 – MySQL 5.7.14 installed and I cm currently working on PHP 7.0. I had the same error. I checked using phpinfo() if both librarires OpenSSL and libssh2 was working(you can google how to check it). After I could see they was working, I have downloaded php_ssh2.dll at http://pecl.php.net/package/ssh2/1.0/windows (can also be found http://windows.php.net/downloads/pecl/releases/ssh2/ ) for the 7.0 version, put it to php\ext folder. Than I included it in php.ini file using extension=php_ssh2.dll.

Then it appeared at phpinfo(). And it worked. Hope it helps.

Maks Z.
  • 21
  • 2
1

Fix that worked for me. Am running xampp v. 3.2.1 apache 2.2 facing the same issue tried placing the dll files at different c: location but failed finally this helped.

1.) Download the version specific dll files from http://pecl.php.net/package/ssh2/0.12/windows and extract the files

Note that even though you are in 64 bit version of windows download the 32 version of THREAD SAFE ssh i.e. Thread Safe (TS) x86 as per your version of php

2.) Add/replace the libssh2.dll at C:\xampp\php (standard installation)

3.) Add/replace the php_ssh2.dll & php_ssh2.pdb within the C:\xampp\php\ext (standard installation)

4.) restart the apache server

Worked Like a charm

CHEERS

akashBhardwaj
  • 149
  • 1
  • 13
  • 1
    Can you please let me know from where can I get libssh2.dll and php_ssh2.dll for Version: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.6 on x86 Architecture. Checking phpinfo.php, it shows me that OpenSSL is enabled. I am finding it hard to get proper dll. Tried many but none works for me. Any help will be appreciated. – tejas033 Mar 02 '17 at 14:43
0

First of all, your question reveals two misconceptions:

  1. The Requirements section actually says this:

    The » OpenSSL and » libssh2 libraries are required. Ensure that the development libraries are installed, where a typical package name might be openssl-dev.

    It isn't talking about PHP extensions, it's talking about third-party libraries that have nothing to do with PHP.

  2. extension=php_ssh2.dll requires that you actually have a file called php_ssh2.dll in your PHP's ext directory and you probably don't have it, mainly because it isn't bundled with PHP.

If we check the Installation chapter we can read that SSH2 is a PECL extension. There're a few links with instructions but I can make a summary of the important info:

  • You need a php_ssh2.dll file that matches your PHP installation.
  • Neither the PHP team nor the PECL team distribute such file.
  • Installing PECL extensions on Windows is hard. You need to download the C source code, grab a C compiler and make the file yourself, or find someone who already did it for you.

Said that, unless you Google for php_ssh2.dll and find something relevant, you're probably out of luck.

Álvaro González
  • 128,942
  • 37
  • 233
  • 325