title: Global environment variable not available to bash command executed inside PHP
body: <p>I'm trying to return the value of a global environment variable inside a bash script which is executed from inside PHP (run as sudo).</p>
  
  <p>Running the command <code>printenv</code> from the bash script reveals that the global variable is not set. I understand sudo resets the environment. </p>
  
  <p>Please consider the following setup;</p>
  
  <p><strong>Define global environment var</strong></p>
  
  <pre><code>root@test:/# export HEY=hello
  </code></pre>
  
  <p><strong>Test existence of var</strong></p>
  
  <pre><code>root@test:/# printenv | grep HEY
  HEY=hello
  </code></pre>
  
  <p>Please consider this PHP function</p>
  
  <p><strong>PHP function</strong></p>
  
  <pre><code>function testAction() {
  
      define('TEST_CMD', '/usr/bin/sudo /usr/local/test/bin/');
      $command = 'bash_script';
      $query = TEST_CMD.$command;
  
      exec ($query, $output, $return_var);
  
      var_dump( $output );
      var_dump( $return_var );
      echo exec('whoami');
  
  }
  </code></pre>
  
  <p><strong>Contents of <code>/etc/sudoers.d/admin</code></strong></p>
  
  <pre><code>admin   ALL=(ALL)       ALL
  admin   ALL=NOPASSWD:/usr/local/test/bin/*
  </code></pre>
  
  <p><strong>Contents of <code>/usr/local/test/bin/bash_script</code></strong></p>
  
  <pre><code>#!/bin/bash
  printenv
  echo $HEY
  exit
  </code></pre>
  
  <p>I have tried putting <code>Defaults   env_keep +="HEY"</code> inside <code>/etc/sudoers.d/admin</code> too but that doesn't appear to work either.</p>
  
  <p>OS is ubuntu 14.04</p>
  
  <p>Any ideas? </p>