PHP Install SSH2 on Windows machine
Asked Answered
P

8

22

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?

Plutonic answered 28/2, 2013 at 11:29 Comment(0)
D
30

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.

Doublecheck answered 10/5, 2013 at 10:39 Comment(6)
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?Tarttan
Got resolved by updating everything and anything in web stack to latest versions. Probably some DLL conflict or whatever.Tarttan
...applied to systems with PHP 5.3.27 and PHP 5.4.15 versions. Worked flawlessly!Peregrinate
I'm using PHP 5.6 and I'm probably out of luck, there's no .dll to download and vc11 isn't compatible.Smukler
@Christian: I'm stuck needing this with PHP5.6 too...if you figure something out, PLEASE let us know :)Lewellen
For PHP 7.1, I had to get from this location: 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.Nighthawk
D
14

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.

Divulge answered 18/10, 2013 at 4:33 Comment(3)
On xampp I had to copy libssh2.dll to C:\xampp\php folder but when I run the script. xamp stops working.Palla
Place the extension DLL file in the "ext" sub folder of PHP instead, where it belongs to.Dian
libssh2.dll is not in the download files! where should I get it?Asphyxia
S
8
  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
Smite answered 17/7, 2014 at 11:29 Comment(1)
I personally (on Windows 7) had to add these libs to C:\Windows\SysWOW64 (on 32bit that is C:\Windows\System32 )Primogeniture
L
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.

Leede answered 21/11, 2016 at 9:31 Comment(1)
The 5.6 x86 version of the DLL contains malware. Do not know about others.Naji
K
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)

Koester answered 16/7, 2014 at 19:26 Comment(0)
D
4

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.

Dayna answered 30/1, 2017 at 8:51 Comment(0)
O
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

Oestrone answered 7/8, 2015 at 6:57 Comment(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.Mallorymallow
R
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.

Revel answered 28/2, 2013 at 13:13 Comment(5)
I have php_ssh2.dll on my server, I've downloaded it here: php.net/releases/#5.2.6 >> PECL 5.2.6 Win32 binariesPlutonic
Maybe you can suggest me another method to SFTP through PHP with key?Plutonic
@Plutonic - Are you using PHP/5.2.6?Pelletier
@Plutonic - There appear to be many questions already. This answer suggests that PHP has builtin support :-?Pelletier
For what it's worth, Windows releases of php_ssh2 are available at windows.php.net/downloads/pecl/releases/ssh2.Finstad

© 2022 - 2024 — McMap. All rights reserved.