title: Bash script being executed in a php script
body: <p>I know there are other posts about this, but I have tried out all the solutions and fixes that were marked as solution and none of them works for me.</p>
  
  <p>As the title says, I am trying to make a php script execute a bash script when being loaded in a web server (apache).</p>
  
  <p>I am using a wrapper as I saw in another post, so here is the wrapper.c:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  
  int main (int argc, char *argv[]) {
      setuid (0);
      system ("/bin/sh /var/www/html/scrip/debugport/testversion.sh");
      return 0;
  }
  </code></pre>
  
  <p>This is the testversion.sh script:</p>
  
  <pre><code>#!/bin/bash
  screen -S skywars -X stuff "stop
  "
  cd /tmp
  pid=$(fuser -n tcp 12321 | awk '{print $1}')
  kill -9 $pid
  </code></pre>
  
  <p>And this is the php code that I am using:</p>
  
  <pre><code>&lt;?php
      $message=shell_exec("./var/www/html/scrip/php_root");
      print_r($message);
  ?&gt;  
  </code></pre>
  
  <p>When I do ./php_root (which is the compiled wrapper.c) everything works fine, but when I try to load it from a web server the script doesn't work at all.</p>
  
  <p>It's probably something to do with the permissions, but I used every permission exactly like in this post's solution: <a href="https://stackoverflow.com/questions/8532304/execute-root-commands-via-php">Execute root commands via PHP</a></p>
  
  <p>The wrapper is supposed to make the script be executed as root no matter what user executes it, but it doesn't work.</p>
  
  <p>Thanks guys.</p>