Apache 服务器上 PHP 开启 SSH2 需要先安装 libssh2 和 ssh2 (php pecl 扩展),libssh2 的官方下载地址:http:/www.libssh2.org/download/ ,ssh2 的官方下载地址:http://pecl.php.net/package/ssh2

下载后解压安装,先安装 libssh2:

# tar -zxvf libssh2-1.4.2.tar.gz
# cd libssh2-1.4.2
# ./configure --prefix=/usr/local/libssh2
# make && make install

安装 libssh2 的时候记住安装目录,因为下面安装 ssh2 的时候还会用到它:

# locate phpize
# /usr/local/php/bin/phpize
# tar -zxvf ssh2-0.12.tgz
# cd ssh2-0.12
# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
# locate php-config
/usr/local/php/bin/php-config
# ./configure --prefix=/usr/local/ssh2 --with-ssh2=/usr/local/libssh2 --with-php-config=/usr/local/php/bin/php-config
# make
# make install 
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
/usr/local/php/lib/php/extensions/no-debug-zts-20131226# ls
memcache.so  mongo.so  opcache.so  redis.so  ssh2.so  xcache.so

把 ssh2 扩展添加到 php.ini 中:

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226/"
extension=mongo.so
extension=redis.so
extension=memcache.so
extension=xcache.so
extension=ssh2.so

重启 Aapache 让配置生效。

参考文章:https://www.cnblogs.com/timelesszhuang/p/4463141.html