5

Operating System used

Windows 7 - V 6.1

Apache installed

httpd-2.2.22-win32-x86-no_ssl.msi

My httpd.conf

AddType application/x-httpd-php .php

LoadModule php5_module "X:/Program Files/PHP/php5apache2_2.dll"

Version of php installed

php-5.3.16-Win32-VC9-x86.msi

I copied the php_ssh2.dll from php_ssh2-0.11.2-5.3-nts-vc9-x86.zip uncompressed

php_ssh2-0.11.2-5.3-nts-vc9-x86.zip

to

X:\Program Files\PHP\ext\php_ssh2.dll

My php.ini

extension_dir="X:\Program Files\PHP\ext"

PHPIniDir "X:/Program Files/PHP"

[PHP_SSH2]
extension=php_ssh2.dll

Apache has been restarted after configuring php.ini with php_ssh2.dll and after copying the file php_ssh2.dll to extension_dir - error persists

Fatal error: Call to undefined function ssh2_connect() in X:\Program Files\Apache Software Foundation\Apache2.2\htdocs\index.php on line 4

code used to test

<?php
$connection = ssh2_connect("XXX.XXX.XXX.XXX", 22);

if(ssh2_auth_password($connection, "XXXXXX", "XXXXXX"))
  printf("CONNECTED");
else
  printf("ERROR");
?>

A test with phpinfo() displays the page perfectly in the browser because php was configured with the httpd.conf but the parameter extension_dir appears as

extension_dir C:\php C:\php

but this parameter was set to "X:\Program Files\PHP\ext"

j0k
  • 22,600
  • 28
  • 79
  • 90
Flavio Moraesjr
  • 73
  • 1
  • 2
  • 5

5 Answers5

3

Enable the corresponding .DLL file to the php.ini (or separate extensions conf if applicable) that is used by PHP: extension=ssh2.dll (remove an ; if it happens to be in front of this line)

We can check if the SSH2 extension for PHP has been enabled by using the windows command line(This might need an apache restart): php -m This will list out all the php extensions installed and you should see ssh2 in it.

You should now be able to use ssh2_connect()

raidenace
  • 12,789
  • 1
  • 32
  • 35
  • I saw an error sent by the output of the command `php-m`. This is `syntax error, unexpected '" in X:\program Files\PGP\php.ini on line 35 `. Line 35 of my php.ini was: `PHPIniDir" X:\Program Files \PHP"`. I put a comment on that line, restarted apache and it worked. I sincerely thank Raidenace your help - Thank you – Flavio Moraesjr Aug 20 '12 at 11:57
1

On your ini file do you see ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp under Registered PHP Streams if not dll is not loaded. Apache restart may be?

Also I assume you had

PHPIniDir "X:/Program Files/PHP"

in httpd.conf not php.ini

David Newcomb
  • 10,639
  • 3
  • 49
  • 62
PoX
  • 1,229
  • 19
  • 32
  • Your observation is correct. This line was the problem. Thank you for your help too PoX. I really appreciate That. – Flavio Moraesjr Aug 20 '12 at 12:01
  • I've been banned from asking questions... `Fatal error: Uncaught Error: Call to undefined function ssh2_connect() in /var/www/html/olevel/Class/O_Cron.php:21 Stack trace: #0 /var/www/html/olevel/Module/test.php(7): Ssh2_crontab_manager->__construct(NULL) #1 {main} thrown in /var/www/html/olevel/Class/O_Cron.php on line 21` And here's the code `$this->connection = @ssh2_connect(DATABASE_HOST, SERVER_PORT);` – Precious Tom May 12 '18 at 19:33
1

Will work for sure.

Run this to install ssh2:

sudo apt-get install libssh2-php

now run this command to check if ssh2 appended to array of extensions

php -r "print_r(get_loaded_extensions());"

now code to move your files

public function movefolder() {



          $connection = ssh2_connect('xxx.xx.xx.xx', 22);

        $res = ssh2_auth_password($connection, 'xxxx', 'xxxx123');


          $res1 = ssh2_scp_send ($connection, '/home/user/public/upgrades/downloaded/abc.tar', '/home/xxx/public/abc.tar', 0644);


           echo $connection . '--' . $res. '--' .$res1;

        die;

    }
CRUSADER
  • 5,486
  • 3
  • 28
  • 64
0
  1. Download php_ssh2-0.11.2-5.3-vc9-x86.zip
  2. Set extension in php.ini
  3. Restart Wamp

This is for Wamp with Apache 5.3 and W32

0

in the php_ssh2-0.11.2-5.3-nts-vc9-x86.zip you have 2 dlls

  1. php_ssh2.dll
  2. libssh2.dll

the first go here
X:\Program Files\PHP\ext\php_ssh2.dll and the second go there X:\Program Files\PHP\libssh2.dll

INPEC
  • 1
  • 1