jquery - Ajax request to PHP page and exec(ssh....) not working -


i posting php page using ajax (ignore data posted, thats not important)

when run php page on linux server using command: php addhit.php correctly echoes out hostname of remote server. not happen in ajax, blank alert success function is. can see in action here: http://ec2-54-244-169-118.us-west-2.compute.amazonaws.com/bootstrap/jumbotron-narrow/index.php

    <script>         $(function() {               $("form[name=addhit]").submit(function() {                   alert("i alert box!");                 var link = $("input[name=link]").val();                 var comments = $("input[name=comments]").val();                 var datastring = "link="+link+"&comments="+comments;                 alert(datastring);                 $.ajax({                     type: "post",                       url: "/bootstrap/jumbotron-narrow/addhit.php",                       data: datastring,                       success: function(data, status, xhr) {                           alert(data);                     },                      error: function(httprequest, textstatus, errorthrown) {                         alert("status=" + textstatus + ",error=" + errorthrown);                     }                 });                   alert("here");                 return false;             });          });       </script> 

my addhit.php page

$commands = "ssh -i adoekey.pem ubuntu@ip-10-250-69-130.us-west-2.compute.internal hostname -f "; echo exec($commands); 

how @archetype2 fixed problem (from post):

i had create folder /var/www/.ssh , copied items /root/.ssh folder new folder , changed ownership of new directory , contents www-data. changed permissions on pem file 400.

getting stderr output command

instead of using exec run command, use following (from "php stderr after exec()"):

$descriptorspec = array(     0 => array("pipe", "r"),  // stdin     1 => array("pipe", "w"),  // stdout     2 => array("pipe", "w"),  // stderr );  $command = "ssh -i adoekey.pem ubuntu@ip-10-250-69-130.us-west-2.compute.internal hostname -f "; $pipes = ''; $process = proc_open($command, $descriptorspec, $pipes, dirname(__file__), null);  $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]);  $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]);  echo "stdout : \n"; var_dump($stdout);  echo "stderr :\n"; var_dump($stderr);  $returncode = proc_close($process); echo "return code: " . $returncode; 

when run php addhit.php command, you're running user you're logged in (root maybe?). http server has it's own user severely limited permissions. server configuration? running lamp stack?

also try use absolute file path .pem file since whatever executing php script may changing current working directory else.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -