Question
How to install ssh extension for PHP?
Answer
For CentOS only
For OS php package:
#cd usr/local/lib/php
- Install all missing packages:
# yum install make gcc glibc-devel zlib-devel openssl-devel php-devel
- Compile and install libssh2 libraries:
# wget https://libssh2.org/download/libssh2-1.8.0.tar.gz
# tar vxzf libssh2-1.8.0.tar.gz
# cd libssh2-1.8.0/
# ./configure
# make
# make install
- Compile and install ssh2 extension:
# wget https://pecl.php.net/get/ssh2-0.13.tgz
# tar vxzf ssh2-0.13.tgz
# cd ssh2-0.13
# phpize
# ./configure --with-ssh2
# make
# make install
- Add extension to PHP:
# echo "extension=ssh2.so" > /etc/php.d/ssh2.ini
- Check that it is working:
# php -m | grep ssh2
ssh2
For Plesk php(5.6 as example):
- Install all missing packages:
# yum install make gcc glibc-devel zlib-devel openssl-devel plesk-php56-devel
- Compile and install libssh2 libraries(not required if it was previously done):
# wget https://libssh2.org/download/libssh2-1.8.0.tar.gz
# tar vxzf libssh2-1.8.0.tar.gz
# cd libssh2-1.8.0/
# ./configure
# make
# make install
- Install ssh2 extension:
# /opt/plesk/php/5.6/bin/pecl install https://pecl.php.net/get/ssh2-0.13.tgz
on 'libssh2 prefix? [autodetect] :' leave empty and press enter
- Add extension to PHP:
# echo "extension=ssh2.so" > /opt/plesk/php/5.6/etc/php.d/ssh2.ini
- Check that it is working:
/opt/plesk/php/5.6/bin/php -m| grep ssh2
ssh2
Note : For Plesk PHP 7.0 it is required to download
ssh2-1.0.tgz
<?php
phpinfo();
?>
ssh2
SSH2 support |
enabled |
extension version |
0.13 |
libssh2 version |
1.8.0 |
banner |
SSH-2.0-libssh2_1.8.0 |
you can use the phpseclib library to connect with SFTP. Examples on how to use the phpseclib can also be found on the phpseclib page.
http://phpseclib.sourceforge.net/
http://phpseclib.sourceforge.net/sftp/intro.html
http://phpseclib.sourceforge.net/ssh/intro.html
http://phpseclib.sourceforge.net/ssh/auth.html#rsakey
Từ khóa: connect sftp in php, ssh2