title: run bash script as root from php page
body: <p>I have a php page.</p>
  
  <p>It calls a validation bash script that checks variables passed from the php page.</p>
  
  <p>I then call another bash script that I need to execute under root user.  I have followed the guide here <a href="https://stackoverflow.com/questions/10915241/how-to-run-from-php-a-bash-script-under-root-user">How to run from PHP a bash script under root user</a> and still can not get script to execute as root.</p>
  
  <p>I have the following:</p>
  
  <p>php page</p>
  
  <pre><code>$bashFile = shell_exec('./Validation.sh "'.$coinName.'" "'.$coinNameAbreviation.'" "'.$blockReward.'" "'.$blockSpacing.'" "'.$targetTimespan.'" "'.$totalCoins.'" "'.$firstBitAddy.'" "'.$seedNode.'" "'.$seedName.'" "'.$headline.'" ');
  echo "&lt;pre&gt;$bashFile&lt;/pre&gt;";
  </code></pre>
  
  <p>the validation file:</p>
  
  <pre><code>sudo nohup /bin/bash /usr/sbin/CoinCreationBashFile "$coinName" "$coinNameAbreviation" "$blockReward" "$blockSpacing" "$targetTimespan" "$totalCoins" "$firstAddyBit" "$seedNode" "$nameSeedNode" "$headline" "$blocksPerDay" "$startingDifficulty" &gt;&gt; /tmp/BASH2log.txt 2&gt;&amp;1 &amp;
  </code></pre>
  
  <p>I have added </p>
  
  <pre><code>www-data ALL=NOPASSWD /usr/sbin/CoinCreationBashFile
  </code></pre>
  
  <p>to the end of the sudo visudo</p>
  
  <p>and did:</p>
  
  <pre><code>chown root:root /usr/sbin/CoinCreationBashFile
  chmod 755 /usr/sbin/CoinCreationBashFile
  </code></pre>
  
  <p>was running it from usr/sbin from suggestion here <a href="http://ubuntuforums.org/showthread.php?t=1848069" rel="nofollow noreferrer">http://ubuntuforums.org/showthread.php?t=1848069</a> 
  Can anyone see what I am doing wrong?? Many thanks
  edit: I can run the CoinCreationBashFile script without the sudo command and it runs ok up to one point where it needs root priv... so i know the script working, and executing from the terminal the script runs perfectly as desired.  output in tmp/BASH2log.txt</p>
  
  <pre><code>sudo: no tty present and noaskpass program specified
  </code></pre>