title: Can't execute Python script from PHP document
body: <p>I am running a PHP document on an Apache server on my Raspberry Pi and I want it to run a file when a button is clicked. I put some echo commands under the command to make the file run and it prints out but the file doesn't run. The index.php file and lightson.py and lightsoff.py files are all in the same directory (<b>/var/www</b>) and I have added <b>#!/usr/bin/env python</b> to the top of both files and made them executable by using <b>chmod +x lightson.py</b>. If I run the command from the shell it works and turns on the light just like I want with the exact same command as in the file but yet it wont run through the command. The code: </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Light Controller&lt;/title&gt;
  &lt;/head&gt;
  
  
  &lt;?php
  if (isset($_POST['LightON']))
  {
  shell_exec("sudo python /var/www/lightson.py");
  echo("on");
  }
  if (isset($_POST['LightOFF']))
  {
  shell_exec("sudo python /var/www/lightsoff.py");
  echo("Off");
  }
  ?&gt;
  
  &lt;form method="post"&gt;
  &lt;button name="LightON"&gt;Light ON&lt;/button&gt;&amp;nbsp;
  &lt;button name="LightOFF"&gt;Light OFF&lt;/button&gt;&lt;br&gt;&lt;br&gt;
  &lt;/form&gt; 
  
  
  &lt;/html&gt;
  </code></pre>