简体   繁体   中英

php script to access remote linux server and execute bash script

I am trying to do the following.

Have php execute shell commands on our remote servers. This because i would like to be able to install scripts through bash So php is going to execute the bash scripts on the remote server.

The issue is the can't connect to the remote server for some reason. I have tried several way to do this and i have to do with the root and password. Later i can look at encrypting them or something like that, but i can't use a ssh key so that is not going to work. I am pretty new to php part of it so i need some help figuring out hot to connect to remote servers.

the code i am trying right now is

  $ip = '37.130.000.00'; 
$user = 'admin'; 
$pass = 'xxxxxxxxx'; 

$connection = ssh2_connect($ip); 
ssh2_auth_password($connection,$user,$pass); 
$shell = ssh2_shell($connection,"uptime");


 echo $shell;

For some reason this code is giving me the following error

Fatal error: Call to undefined function ssh2_connect() in

How can i make this work or what else should i do to properly connect to the remote servers and this all should be very flexible as we are talking around 100 server who should be able to connect this way.

Thanks for any input.

That function is provided by an optional extension that you don't seem to have installed. Provided you have libssh and other dependencies in your system, get pecl-ssh by executing

sudo pecl install ssh2 channel://pecl.php.net/ssh2-0.11.3

and then restart php-fpm or apache if you're using modphp.

Edit: btw, this question has been asked before and one of the wisest advises I've seen in regards to is was to switch over to a pure php implementation, no pecl extensions whatsoever: php-function-ssh2-connect-is-not-working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM