2016/05/24

CentOS7 ssh2_connectを実装する

正規の方法でインストールを試みるが、

#pecl install ssh2
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/msql.so' - /usr/lib64/php/modules/msql.so: cannot open shared object file: No                                                            
such file or directory in Unknown on line 0
PHP Warning:  Module 'mbstring' already loaded in Unknown on line 0
PHP Warning:  Module 'pgsql' already loaded in Unknown on line 0
Failed to download pecl/ssh2 within preferred state "stable", latest release is version 0.12, stability "beta", use "channel://pecl.php.net/ssh2-0.12" to install install failed

エラー

ネイティブな解説ページが有ったので、
参考にしながら実装までのオボエガキ


先ずは、yumを最新にする。

# yum update

# yum install make gcc libssh2 php-deve

# pecl install -f ssh2
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/msql.so' - /usr/lib64/php/modules/msql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  Module 'mbstring' already loaded in Unknown on line 0
PHP Warning:  Module 'pgsql' already loaded in Unknown on line 0
WARNING: failed to download pecl.php.net/ssh2 within preferred state "stable", will instead download version 0.12, stability "beta"
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading ssh2-0.12.tgz ...
Starting to download ssh2-0.12.tgz (26,223 bytes)
.........done: 26,223 bytes
6 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
libssh2 prefix? [autodetect] :     ←ここはブランクのまま エンターした。
Build process completed successfully
Installing '/usr/lib64/php/modules/ssh2.so'
install ok: channel://pecl.php.net/ssh2-0.12
configuration option "php_ini" is not set to php.ini location
You should add "extension=ssh2.so" to php.ini

となるので、

# echo "extension=ssh2.so" > /etc/php.d/ssh2.ini

httpdを再起動させる。

# systemctl restart httpd.service

# php -m | grep ssh2
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/msql.so' - /usr/lib64/php/modules/msql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  Module 'mbstring' already loaded in Unknown on line 0
PHP Warning:  Module 'pgsql' already loaded in Unknown on line 0
ssh2

phpinfo() で確認すると

ssh2

SSH2 supportenabled
extension version 0.12
libssh2 version 1.4.3
banner SSH-2.0-libssh2_1.4.3

となり、実装完了。

実装方法




<?php
$connection = ssh2_connect('アドレス', 22);
ssh2_auth_password($connection, 'ログインユーザ名', 'ログインパスワード');

ssh2_scp_send($connection, '../転送元ファイル', '転送先ディレクトリ/転送するファイル', 0644);
?>

0 件のコメント:

コメントを投稿