//
you're reading...
IT-Center, PHP, Web Based

SSH Using PHP

Install SSH2 PHP in Centos 6.5

Before we start, please ensure that you have the EPEL repo installed. If you don’t, goto http://fedoraproject.org/wiki/About_EPEL to get instructions.

Firstly, we’re going to install the dependencies:

yum install gcc php-devel php-pear libssh2 libssh2-devel

These will allow us to build the SSH2 extension using pecl.

pecl install -f ssh2

After running that command, it should stop at a line like:

..
........done: 22,740 bytes
5 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
libssh2 prefix? [autodetect] :

All you have to do is hit Enter and it should detect the proper path. Once the install is completed, you just have to tell PHP to load the extension when it boots.

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

Now restart your webserver and test to see if the changes took effect.

/etc/init.d/httpd restart
php -m | grep ssh2

You should get a line returned with ‘ssh2’.

Installing SSH2 PHP in Ubuntu

Install library using sudo.

sudo apt-get install libssh2-php

Next.. restrart apache and code your scritp

sudo /etc/init.d/apache2 restart

 

TESTING :

<?php

error_reporting(E_ALL);
ini_set(‘display_errors’, 1);
$connection = ssh2_connect(‘103.28.xxx.xxx’, 22);
ssh2_auth_password($connection, ‘root’, ‘xxxx’);
$q=ssh2_scp_send($connection, ‘/var/www/html/eticketing/upload/code.xls’, ‘/var/www/html/test/code.xls’, 0644);
?>

About berbagisolusi

Berbagi merupakan sebuah bentuk simbol keikhlasan untuk membantu dan menolong, sedangkan solusi adalah cara menyelesaikan masalah. Setiap manusia pasti mengalami masalah, tetapi kita tidak perlu mengalami masalah yang sama jika orang lain pernah mengalami dan kita tahu hal tersebut.

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

October 2015
M T W T F S S
« Sep   Jul »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Web Statistic

Blog Stats

  • 149,580 hits
%d bloggers like this: