title: PHP shell_exec doesn't execute
body: <p>I'm having this huge headache that is making some buttons on my webserver that stops/start/restart my ElasticSearch service when needed.
  I've looked up a lot on the internet and not found anything like my problem.</p>
  
  <p>Here is the shell that I'm trying to execute:</p>
  
  <pre><code>if(isset($_POST["name"])){
  
  $name = $_POST["name"];
  
  //the script to check the service status of ElasticSearch (which works fine btw)
  $status = shell_exec("systemctl status elasticsearch");
  
  //I use a simple regex to get from the above script's output if the status of the service is "running" or not
  preg_match("/\bactive\s+\K\S+/", $status, $result);
  
  switch ($name){
      case "start":
          $shell = shell_exec("sh ../../../../scripts/startElasticsearch.sh");
          echo $shell;
          if($result[0] == "(running)"){
              echo "Node started successfully.";
          }
          break;
      case "restart":
          $shell = shell_exec("sh ../../../../scripts/restartElasticsearch.sh");
          echo $shell;
          if($result[0] == "(running)"){
              echo "Node restarted successfully.";
          }
          break;
      case "stop":
          $shell = shell_exec("sh ../../../../scripts/stopElasticsearch.sh");
          echo $shell;
          if($result[0] !== "(running)"){
              echo "Node stopped successfully.";
          }
          break;
  }
  }
  </code></pre>
  
  <p>This is the shell script of the 3 .sh files that I wrote:</p>
  
  <pre><code>#!/bin/bash
  systemctl start elasticsearch
  
  #!/bin/bash
  systemctl restart elasticsearch
  
  #!/bin/bash
  systemctl stop elasticsearch
  </code></pre>
  
  <p>I've already changed all permissions to execute the shell (like chmod 755 and so on...).</p>
  
  <p>Now here is the trippy part: when I was debugging the execution of the shell, I've tried to <code>echo</code> a "Hello World" so I can be sure that my php script was working fine (since <code>systemctl start/restart/stop elasticsearch</code> doesn't output anything)
  And it worked all fine. I've got the "Hello World" answer from the script on a toast when clicked the button. But nothing else from the 3 scripts above (I was monitoring the service status via Kibana).</p>
  
  <p>Any ideas?</p>