title: Execute php file from website after clicking a button (apache)
body: <p>The php file is in web site directory (<code>/var/www</code>) and I would like to execute it from <code>index.html</code> which is in the same directory.</p>
  
  <p>The php file:</p>
  
  <pre><code>    &lt;?php
      exec("sudo -u pi /home/pi/camcv/camcv .. ");
      ?&gt;
  </code></pre>
  
  <p>Can be run by typing <code>php /var/www/script.php</code> in command line from anywhere in the system, it executes properly (camera flashes, opens the window with picture, no errors). I would need it to be executable by <code>www-data</code> user from website.</p>
  
  <p>I know there are many options, I have tried <code>submit</code> forms, <code>onClick</code> actions, sending a parameter ( <code>$_POST['xy']</code>) then watching it with "if" structure in php file, <code>AJAX</code> in form of <code>XMLHttpRequest</code> and in form of <code>$.ajax</code> , I tried to include javascript <code>jquery.min.js</code> and have tried to add permissions in <code>sudoers</code> or changed ownership of folders/files with allowing to read/write/execute... all without achieving the goal.</p>
  
  <p>So my questions are:</p>
  
  <p>-Does someone have a bulletproof way to make this work ?</p>
  
  <p>-Can you tell me what exactly do I have to add in <code>sudoers</code> ? </p>
  
  <p>Thanks for any advice.</p>
  
  <p>PS: Few of the tries did redirect me to page <code>http://(ip)/script.php</code> so there is at least some response from the buttons. Also, XMLHttpRequest did work on Changing the text on webpage (reading and posting txt file).</p>
  
  <p>PSS: The function does not require any return information, I would need the page to stay on the site with the button, possibly not reloading.</p>