I am running Xampp on a Mac with OS X 10.9.1 and I am trying to develop a web page that calls a PHP script through an Ajax call. Xampp is used here for development purposes and it is not intended to form the backend of an online page.
A PHP script needs to connect though ssh to a remote machine, reason for which I
plan to use the ssh2 library. When I try to run the commands:
$connection = ssh2_connect('my.remote.machine.address', 5432);
I get the following error:
Fatal error: Call to undefined function ssh2_connect() in /Applications/XAMPP/xamppfiles/htdocs/Project/getdata.php on line 8
and, by calling 'phpinfo()', ssh2 does not seem to be installed. I successfully managed to use ssh2_connect on Windows, Ubuntu and Scientific Linux and after a week I can't seem to figure out what I'm not doing right on a OSX I suspect there could be a problem with broken paths or interaction with the Apache server OSX came with. Here is what I have tried:
I. The MacPorts and PECL method (reference: http://lassebunk.dk/2011/05/26/installing-ssh2-for-php-on-mac-os-x/):
sudo apachectl stop
so that the Xampp one worked.
sudo port install libssh2
as the libssh2 and openssl libraries are prerequisites to using ssh2_connect in php (reference: http://www.php.net/manual/en/ssh2.requirements.php); openssl appears to be already installed on Xampp's according to phpinfo().
sudo php /usr/lib/php/install-pear-nozlib.phar
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
brew install autoconf
$ sudo pecl install ssh2-0.12
with "/opt/local" as prefix
/Applications/XAMPP/xamppfiles/etc
by adding the line:
extension=/opt/local/lib/php54/extensions/no-debug-non-zts-20100525/ssh2.so
II. The compile the ssh2.so from the terminal method (reference: zizifu's comment http://www.php.net/manual/en/ssh2.installation.php):
./configure
make
make install
phpize
./configure --with-ssh2
make
make install
Sorry if this has too much detail, hopefully the information I gave can point what I'm doing wrong; I would really appreciate any solution/hint/thing to try to solve this issue.
Have you considered phpseclib, a pure PHP SSH2 implementation? It has a number of advantages over libssh2, including improved portability and speed. Example:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>