title: Accessing USB webcam via a PHP script on Linux/Apache
body: <p>I want to use a USB webcam (in a small C++/OpenCV application) and call it from a PHP script. My test app looks like this:</p>
  
  <pre><code>int main( int argc, char **argv )
  {
      cv::VideoCapture C( 0 );
  
      cout &lt;&lt; "C.isOpened() = " &lt;&lt; boolalpha &lt;&lt; C.isOpened() &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>The PHP script looks like this:</p>
  
  <pre><code>&lt;?php
  exec( escapeshellcmd( '/thepath/theapp' ), $output, $result );
  
  var_dump( $output );
  ?&gt;
  </code></pre>
  
  <p>When I call this app directly from the command line, it returns <strong>true</strong>. </p>
  
  <p>When I call the app via php like this <code>php -f /the_php_script.php</code> it returns <strong>true</strong>.</p>
  
  <p>When I call the app via php called by AJAX from a html file (with a button), it passes through Apache and then returns <strong>false</strong>.</p>
  
  <p>So, my app works fine. My php script works fine too. But there is a permission or something like this that prevents php, via Apache to access the webcam (to initialize it with OpenCV library), <em>but the permission is sufficient to allow the app to run</em>.</p>
  
  <p>Could someone help me? Any idea?</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Following a suggestion, I tried to used a php script to start my app without the use of AJAX. I obtained the same results, i.e. OpenCV <em>cannot</em> initialized the USB webcam on the server.</p>