centos php ssh2 扩展,CentOS下PHP的SSH2扩展安装方法

下载地址

wget http://www.libssh2.org/download/libssh2-1.4.2.tar.gz

wget http://pecl.php.net/get/ssh2-0.12.tgz

先安装 libssh2 在安装 SS2

# tar -zxvf libssh2-1.4.2.tar.gz

# cd libssh2-1.4.2

# ./configure --prefix=/usr/local/libssh2

# make && make install

以上为安装libssh2,这里需要记住libssh2的安装目录,因为在安装ssh2的时候还会用到。

# tar -zxvf ssh2-0.12.tgz

# cd ssh2-0.12

# phpize

# ./configure --prefix=/usr/local/ssh2 --with-ssh2=/usr/local/libssh2

# make

SSH安装

# tar -zxvf ssh2-0.12.tgz

# cd ssh2-0.12

# phpize

# ./configure --prefix=/usr/local/ssh2 --with-ssh2=/usr/local/libssh2 --with-php-config=/usr/local/php/bin/php-config

# make && make install

安装完成之后SSH2扩展在 /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/ 目录中

修改php.ini文件加入

extension=ssh2.so

啊哈哈加入扩展成功

$user="root";//远程用户名

$pass="123456";//远程密码

$connection=ssh2_connect('192.168.1.46',22);

ssh2_auth_password($connection,$user,$pass);

$cmd="ps aux";//命令    $ret=ssh2_exec($connection,$cmd);    stream_set_blocking($ret, true);    echo (stream_get_contents($ret)); //print_r(phpinfo());?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值