recently i need to install ssh2 connection through my php code to connect remote server by sftp for file transfer. i’m using php 7.2 and face a “sigment fault” issue for normal installation. i solved this issue by install required demon. hope it may help someone who face same issue.
first you need to install/upgrade some basic program
apt-get install gcc make autoconf libc-dev pkg-config
then install base library
apt-get install libssh2-1i’m not sure that if you only need to install libssh2-1-dev. but i installed both
apt-get install libssh2-1-dev
now install required php modules
apt-get install php7.2-dev php-pear
now install ssh by pecl (the most important part of installation)
— pecl channel-update pecl.php.netignore commented line OR use if you understand by yourself
— pear config-set php_ini /etc/php/7.2/apache2/php.ini
— pear config-set temp_dir /etc/php/temp/pear
pecl install ssh2-1.1.2
now another important part is your PHP code. when we use ssh2 in fopen wraper, in other version of ssh2 connection we need to open a connection and we can use resource id. but with the above change you must use user, password, port i.e. full access information every time we need to connect to server. here is my sample code –
$fh = @fopen(‘ssh2.sftp://’ . $this->user.’:’.$this->pass.’@’.$this->ip.’:’.(intval($this->port)>0?intval($this->port):22) . $pRemoteLocation, $pMode);
all other code like directory creation or any other command execution may be same as before.