linux下 php 配置ssh扩展

下载这个就行

下载最新的

1. 下载到本地 然后上传到服务器上面
# tar -zxvf libssh2-1.8.0.tar.gz
# cd libssh2-1.8.0
# ./configure --prefix=/usr/local/libssh2 (这里可能会提示命令不存在 直接百度提示的错误就可以了)
# make && make install
以上为安装libssh2,这里需要记住libssh2的安装目录,因为在安装ssh2的时候还会用到。
# tar -zxvf ssh2-1.1.2.tgz
# cd ssh2-1.1.2
# phpize (这里可能会提示命令不存在 直接百度提示的错误就可以了)
# ./configure --prefix=/usr/local/ssh2 --with-ssh2=/usr/local/libssh2
# make

执行完以上过程后,在当前目录下的modules目录下会生成一个ssh2.so文件,这就是扩展PHP所需要的,将该文件拷贝到PHP库的存储目录下在修改PHP的配置文件即可。
# cp modules/ssh2.so /usr/lib64/php/modules/
注:PHP库的存储目录可能因系统而异,本机器上是/usr/lib64/php/modules/
# vi /etc/php.ini
# 向该文件中添加内容:extension=ssh2.so
此时为PHP扩展SSH2就已经完成了,为了验证是否安装成功,我们可以通过执行一下命令来验证。

重启服务和重启php

php -m

测试一下
  1. $connection = ssh2_connect("192.168.6.222",22);  
  2. if (ssh2_auth_password($connection,"veno","ubuntu"))  
  3. {  
  4.          echo "Authentication Successful! ";  
  5. }else{  
  6.          die("Authentication Failed...");  
  7. }  


(可能会出现的问题的参考网址和解决办法)
configure: error: in `/var/libssh2-1.8.0':
configure: error: no acceptable C compiler found in $PATH

解决configure: error: OpenSSL Crypto library not found

crypto是什么呢? 是OpenSSL 加密库(lib), 这个库需要openssl-devel包 ,在ubuntu中就是 libssl-dev 

RedHat Fedora 平台 
yum -y install openssl-devel 

Debian ,ubunu 平台 
apt-get install libssl-dev

Can't find PHP headers in /usr/include/php The php-devel package is required for use of this command.   
用phpize安装pcntl扩展时遇到错误:
Can't find PHP headers in /usr/include/php
The php-devel package is required for use of this command.
解决办法:
yum install php-devel
注意自己的php版本


PHP报错:Error: php71w-common conflicts with php-common-5.4.16-43.el7_4.x86_64 解决方法
环境: LNMP,手动安装的PHP7环境;
 
问题:
php在安装扩展的时候。无论输入php-* 任何来安装扩展,都会报错:
Error: php71w-common conflicts with php-common-5.4.16-43.el7_4.x86_64
 
解决办法:
要用指定PHP版本来安装,比如上面报错的是:php71w,那么你就需要执行:
php71w-*
这样就会安装成功了!
 
原因:
由于我的linux系统默认的php版本是5.4,如果你手动安装的环境,就要处理这个问题了。



参考网址:

猜你喜欢

转载自blog.csdn.net/sunsijia21983/article/details/80944369