title: Starting shell process under www-data (apache2, php)
body: <p>I need to start php process from shell on remove server with some arguments, so i thought that it should be a nice idea to make REST API, that executes some function when user performs GET request.</p>
  
  <p>I wrote a simple bash script for testing and figured out that command-line argument is not being specified, when calling this script from website:</p>
  
  <pre><code>shell_exec('/var/www/test.sh 123')
  </code></pre>
  
  <p>Bash script source:</p>
  
  <pre><code>#!/bin/sh
  echo $1;
  </code></pre>
  
  <p>When calling this bash script from root (or other existing user) it correctly shows argument it has received. When i call this script from website (that is running under user www-data under apache2), it returns nothing:</p>
  
  <p>Also, if i execute this bash script in my console under www-data user, it also returns nothing:</p>
  
  <pre><code>su -c '/var/www/test.sh 123' www-data
  </code></pre>
  
  <p>Also i've tried to start process from different user from php (is supposed that this will not work for security reasons, but just in case):</p>
  
  <pre><code>$result = system("su -c '/var/www/test.sh 123' sexyuser", $data);
  // var_dump($result): string(0) ""
  // var_dump($data): int(1)
  </code></pre>
  
  <p>So, what privileges should i give to www-data user to run process under php?</p>