title: How to get the full path to php interpreter / binary without shell access
body: <p>How can I get the full path to php interpreter from a php script (no command line access).</p>
  
  <p>What I need to do is:</p>
  
  <pre><code>$foo = "/usr/bin/php";
  echo $foo;
  </code></pre>
  
  <p>But I need to get the path first so I can assign it to foo. </p>
  
  <p>If you have a solution that works on both Windows and nix even better but if not, nix would be fine.</p>
  
  <p>Before you ask,</p>
  
  <ol>
  <li>Asking the host is out of the question</li>
  <li>No shell access</li>
  </ol>
  
  <p>The problem is that using whatever it outputs doesn't work. For example PHP_BINDIR will output /usr/bin but using /usr/bin/php won't help. The full code is:</p>
  
  <pre><code>exec("php-cli $path_to_file &gt; /dev/null 2&gt;/dev/null &amp;"); 
  </code></pre>
  
  <p>But even using the /usr/bin/php-cli doesn’t work even though it tells me that. I have to use:</p>
  
  <pre><code>exec("/opt/php52/bin/php-cli $path_to_file &gt; /dev/null 2&gt;/dev/null &amp;");
  </code></pre>
  
  <p>For this particular host for example.</p>