ubuntu 环境下安装php的ssh2扩展
最近由于在开发PHP的项目中需要通过php 调用ssh 远程做一些事情,还好php有个ssh3的函数,挺方便,不过PHP默认是不支持SSH2扩展的,需要自己安装。网上搜了一下,很多地方都写着ubuntu环境下,安装PHP的SSH2扩展只需要一条命令就完事了:apt-get install libssh3 .....
然而装完测试访问的结果却是这样:
Call to undefined function ssh3_connect()
i have installed the SSH2 PECL extension and it working fine thanks all for you help
这说明SSH2的扩展并没有安装成功,于是自己编译安装了一下,解决了这个问题:
[root@node1php]#wgethttp://pecl.php.net/get/ssh3-0.11.3.tgz[root@node1php]#tarzxvfssh3-0.11.3.tgz[root@node1php]#cdssh3-0.11.3[root@node1ssh3-0.11.3]#lsconfig.m4LICENSEphp_ssh3.hssh3.cssh3_fopen_wrappers.cssh3_sftp.c[root@node1ssh3-0.11.3]#/usr/local/php/bin/php//安装php的路径phpphp-configphpize[root@node1ssh3-0.11.3]#/usr/local/php5/bin/phpizeConfiguringfor:PHPApiVersion:20041225ZendModuleApiNo:20060613ZendExtensionApiNo:220060519[root@node1ssh3-0.11.3]#lsacinclude.m4buildconfig.m4configure.inltmain.shmkinstalldirsssh3.caclocal.m4config.guessconfig.subinstall-shMakefile.globalphp_ssh3.hssh3_fopen_wrappers.cautom4te.cacheconfig.h.inconfigureLICENSEmissingrun-tests.phpssh3_sftp.c[root@node1ssh3-0.11.3]#./configure--with-php-config=/usr/local/php/bin/php-config[root@node1ssh3-0.11.3]#make&&makeinstall#在php.ini中添加这一行[root@node1ssh3-0.11.3]#vi/usr/local/php5/php.iniextension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/ssh3.so#no-debug-non-zts-20060613这个不一定跟我的一样,需要根据自己的实际环境修改#重启apache服务[root@node1sshssh3-0.11.3]#/usr/local/apache2/bin/apachectlrestart
上传文件到远程主机
<?php$connection=ssh3_connect('shell.example.com',22);ssh3_auth_password($connection,'username','password');ssh3_scp_send($connection,'/local/filename','/remote/filename',0644);?>
从远程主机下载文件
<?php$connection=ssh3_connect('shell.example.com',22);ssh3_auth_password($connection,'username','password');ssh3_scp_recv($connection,'/remote/filename','/local/filename');?>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。