title: how to do a linux reboot from php file
body: <p>I have a user brftv on my linux system and I have www-data that runs the nginx.</p>
  
  <p>from the terminal I can let my brftv user run </p>
  
  <pre><code>sudo /sbin/reboot
  </code></pre>
  
  <p>and it works fine since I added the following to my /etc/sudoers file's "#user privilege specification" section:</p>
  
  <pre><code>brftv ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff
  www-data ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff
  </code></pre>
  
  <p>But when my php file runs the following code, nothing happens</p>
  
  <pre><code>exec('nohup sudo -u brftv /sbin/reboot');
  </code></pre>
  
  <p>I added the www-data line to the etc/sudoers above in case it was necessary when running the above exec() (even though I run it as -u brftv, but I'm no linux expert, just thought better be safe just in case).</p>
  
  <p>The php file that runs this exec() is owned by www-data, and chmod is 777, all should thus have privilege to execute from it.</p>
  
  <p>I have tried running the php-file both through browser (would be run by user www-data I assume) and from terminal $ <code>php myFile.php</code>.</p>
  
  <p>------------------- UPDATE -----------------</p>
  
  <p>I did this</p>
  
  <pre><code>sudo chmod u s /sbin/reboot
  </code></pre>
  
  <p>Which allows all users on my system to run the reboot cmd without password. It works, but I rather not leave it THAT open, so the other solution with /etc/sudoers would be better, if someone would have a hint at what my problem is...</p>
  
  <p>I followed this tut <a href="http://linux.byexamples.com/archives/315/how-to-shutdown-and-reboot-without-sudo-password/" rel="noreferrer">http://linux.byexamples.com/archives/315/how-to-shutdown-and-reboot-without-sudo-password/</a> and the second example is pretty much what I got above that didn't work for me..</p>