SSH2 PHP Extension - php

I have been trying for a while to get the SSH 2 extension for php installed on my CentOS 5.6 x64 server. I started the server from scratch and here are the steps I have taken
install and configure APF
install apache
install php
install mysql
add epel repository
install php-pear so I can use pecl
run yum install libssh2-devel
run pecl install ssh2-beta
echo extension=ssh2.so>>/etc/php.ini
(There were a few extra things in there such as installing phpMyadmin and wordpress)
After this I run php -m to see the php modules and ssh2 is not listed. I have been searching forever for tutorials and have found a few but from what I can see I have done everything correctly. Can anyone see where I am going wrong. I can provide any config files you may need. Also I have hear about phpseclib and was wondering if this would be an easier/better route? Any help would be greatly appreciated!

You could maybe try phpseclib, a pure PHP SFTP implementation, instead. eg.
<?php
include('Net/SFTP.php');
$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
echo $sftp->pwd() . "\r\n";
$sftp->put('filename.ext', 'hello, world!');
print_r($sftp->nlist());
?>

Make sure /etc/php.ini is actually used. check php --info output to see the used ini file(s)
At least on debian the path would be /etc/php5/cli/php.ini

Maybe there's no difference, but if not already like this, try:
extension="ssh2.so"

Related

ssh2_connect is undefined on debian

i have several server in debian 6.0.8 with php version at 5.3.28-1~dotdeb.0.
I have made an apt-get install libssh2-php on each.
When u made an php -v, i have openssl and ssh2 in the list on each.
I have already restarted apache after that.
But when i run a php script with ssh2_connect() call, it doesnt' work on 2 servers but it works on the other server.
I have the error : "call to undefined function ssh2_connect()."
I don't understand, debian version and php version are the same.
Can you help me ?
Thanks.
In packaged distros like Debian and EL you have the "non-core" parts of PHP packaged separately. In Debian flavors you have to have the php5-ssh2 package installed.
sudo apt-get install php5-ssh2
I'd just use phpseclib, a pure PHP SSH implementation. eg.
<?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');
?>
phpseclib has a number of a advantages over libssh2. You can also use phpseclib to emulate the libssh2 functions, if you're so inclined. eg.
https://github.com/phpseclib/libssh2-compatibility-layer

undefined ssh2 in php with apache on debian

Debian : 7.4
I have some difficulty to make ssh2 work with php5. i didn't find a solution on other topics and i search a LOT ! all has been well installed according to debian outputs but it still doesn't work.
This is what i'v done
Package installed :
- php5
- php5-dev
- libssh2-php
- libssh2-1-dev
I used PECL to install
pecl install -f ssh2
I just press enter for auto prefix.
And extension=ssh2.so to /etc/php5/apache2/php.ini
Restart more than one time apache2.
But the package ssh2 still not appear in output of php -m and says that ssh2_connect is undefined
I totally out of resources to make it works, so please can anybody helps me ?
Here some info provided by phpinfo() :
extension_dir /usr/local/lib/php/extensions/no-debug-non-zts-20100525/
extension version 0.12
libssh2 version 1.4.3
banner SSH-2.0-libssh2_1.4.3
If you need i can give more informations
I use phpseclib's libssh2-compatibility-layer to avoid having to install libssh2. You can use all the libssh2 functions without having it installed thanks to the use of phpseclib.
If you're writing your application from scratch maybe try just using phpseclib from the onset intsead of libssh2.

PECL Adding gearman to php extension

Hi i'm really having a hard time here,
I'm trying to install gearman job/task queue. I'm using windows, wappstack to be exact, then followed exactly the instructions here, and so far so good. I think I've installed the gearman server.
But I can't seem to find how to actually install PECL extension for gearman. I mean I can't find any .dlls to add to the PHP ext folder. and the PECL Package here just makes me all the more clueless. I can't invoke Gearman classes, and when I use phpinfo(); , gearman extension is just not present. I'm absolutely clueless on this.
How do I add and properly set up gearman extension to my PHP? Please and Thank you!
To you install a extensions of PECL you need use the cmd.
Open the cmd.
Go to directory where is the PHP program.
Find for "pecl.exe"
Install gearman extension.
Like:
$ cd C:/BitNami/wappstack-[version]/php/
$ pecl install gearman
Now, looking for the "php_gearman.dll" in the extension directory.
And add extension to php.ini
http://php.net/manual/en/install.windows.extensions.php
http://php.net/manual/en/install.pecl.php

Installing SSH2 for PHP to run on a Xampp Apache server on a OSX 10.9.1

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/):
stuff already on my computer: xcode (from iStore), MacPorts (installer from their site), PHP 5.4.17 and apparently an Apache server that comes with OSX, that I had to stop with:
sudo apachectl stop
so that the Xampp one worked.
ran the command:
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().
installed Pear:
sudo php /usr/lib/php/install-pear-nozlib.phar
installed Homebrew (otherwise the 'pecl install' commands fail):
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
ran:
brew install autoconf
now I was finally able to run:
$ sudo pecl install ssh2-0.12
with "/opt/local" as prefix
now I got a nice ssh2.so file, which I add to the relevant php.ini:
/Applications/XAMPP/xamppfiles/etc
by adding the line:
extension=/opt/local/lib/php54/extensions/no-debug-non-zts-20100525/ssh2.so
restarted the Xampp Apache Web Server from the GUI that comes with Xampp and still ssh2 was not found.
II. The compile the ssh2.so from the terminal method (reference: zizifu's comment http://www.php.net/manual/en/ssh2.installation.php):
got the libssh2 archive from http://libssh2.org/ and:
./configure
make
make install
got the latest ssh2 archive from http://pecl.php.net/package/ssh2
phpize
./configure --with-ssh2
make
make install
got a ssh2.so file again, added it to the relevant php.ini, restarted server and it still doesn't work.
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');
?>

Pear SOAP and XAMPP on Ubuntu

All,
I have installed xampp for linux on ubuntu 9.10. The installation directory is /opt/lampp. The xampp website says PEAR comes with the installation.. I am relatively new to PEAR and want to know the answers for following:
Is PEAR installed with xampp or need to be installed separately using synaptic package manager? I browse to /opt/lampp/bin directory and see "pear" there, but when i type it in the command line, it says
"The program 'pear' is currently not installed. You can install it by typing:
sudo apt-get install php-pear
pear: command not found
"
I want to use PEAR:SOAP package in my PHP code. How to use that? Do I need to set any paths to the pear in my php.ini?
Thanks
I figured it out.. xampp comes with pear... So, what I did was..
cd /opt/lampp/bin
sudo ./pear install soap
In PHP code, "require_once("SOAP/Client.php");
That's all !! :)
from what I was able to ascertain from my coleagues, you would need to populate pear to be able to use it.
It does come with the installation, but requires the population to be used.
source for code
First, go to your xampp installation
directory/folder and navigate to the
php directory. For me it’s
x:\xamplite\php
x:
cd \xampplite\php
pear install <package-name>
once this is done pear should be available to be used. And as for the second question. XAMPP should have taken care of any settings that were needed. You should not require any additions into the .ini for it to work.
However remember that there are no secuiritis when programming in this fashion, as stated by the XAMPP website.
EDIT**
also you have Pear Ubuntu install guide link that may help.
The error message you got back should be enough. Apparently the pear program isn't in your path. How did you install XAMPP? Did you use the package manager, or did you install it yourself?
If you used the package manager, then this is the correct next step:
sudo apt-get install php-pear
As you were given in the command help. Ubuntu doesn't install a lot of things by default, but it does install a database of stuff you might type, and what package you need to install to get that command to work.
If you installed it yourself, then you need to figure out how to get PEAR to register as being installed.

Categories