title: export shell environment variable before running command from PHP CLI script
body: <p>I have a script that uses <a href="http://www.php.net/manual/en/function.passthru.php" rel="noreferrer">passthru()</a> to run a command. I need to set some shell environment variables before running this command, otherwise it will fail to find it's libraries.</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>putenv("LD_LIBRARY_PATH=/path/to/lib");
  passthru($cmd);
  </code></pre>
  
  <p>Using <a href="http://www.php.net/manual/en/function.putenv.php" rel="noreferrer">putenv()</a> doesn't appear to propagate to the command I'm running. It fails saying it can't find it libraries. When I run <code>export LD_LIBRARY_PATH=/path/to/lib</code> in bash, it works fine.</p>
  
  <p>I also tried the following (in vain):</p>
  
  <pre><code>exec("export LD_LIBRARY_PATH=/path/to/lib");
  passthru($cmd);
  </code></pre>
  
  <p>How can I set a shell variable from PHP, that propagates to child processes of my PHP script?</p>
  
  <p>Am I limited to checking if a variable does not exist in the current environment and asking the user to manually set it?</p>