Enable SSH2 in PHP on Windows

Anything that you do with PHP on Windows that is outside of the standard install is always an adventure. Especially installing extensions. This Law of PHP on Windows was again confirmed when I tried to enable SSH2 in PHP 5.3.3 on my Windows machine.

To save you time, here are the steps:

  • Determine which version of PHP you have: x64 or x32, as well as Thread Safe vs. Non-Thread Safe
  • C:\tmp>php -i > info.txt
  • then open info.txt and take note of the “Architecture” as well as the “Thread Safety” (enabled means you need the TS version)
  • Download the SSH2 related files for your version and whether your local install is TS or NTS
  • http://pecl.php.net/package/ssh2/0.12/windows
  • Unzip to your directory of choice
  • Copy libssh2.dll to C:\Windows\System32
  • if on a x64 system, you’ll also need to copy it to C:\Windows\SysWOW64
  • Copy php_ssh2.dll and php_ssh2.pdb to your PHP install directory’s /ext directory (e.g. C:\dev\php\5.3.3\ext)
  • Restart Apache

To test if SSH2 is installed, re-run the “php -i > info.txt” command and ensure that ssh2 related items are listed within the “PHP Streams” section.

Also, you can verify it within your code by running something like:

        if (!function_exists('ssh2_connect')) { 
            echo "ssh2 is not configured properly"
        }
About the Author

Sean

View Posts →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.