title: Restarting a Linux Server via Web Browser (PHP)
body: <p>After opening and reading every result on Google, I figured it's time to make my own thread somewhere. <em>I am sorry that I need to ask a question that's already been asked before, I cannot stress this enough, but I have no other option as no other question asked has helped me achieve what my goal is.</em></p>
  
  <p>I'm trying to setup a means of rebooting/doing other system functions through a web interface powered by HTML (for the buttons/text) and PHP (for the execution of the aforementioned functions).</p>
  
  <p>I'm unable to get this to work. I've read that I need to add the web user to the sudoers file, and I've tried. I'm running Nginx on my server, how do I add the user to the sudoers in my case?</p>
  
  <p>Also, I'm aware of the security risks.</p>
  
  <p>The following is what I have so far:</p>
  
  <p><strong>HTML (index.html):</strong></p>
  
  <pre><code>&lt;body&gt;
  
  &lt;h3&gt;Restart&lt;/h3&gt;
  &lt;p&gt;
  &lt;form action="restart.php" method="get"&gt;
    &lt;input type="submit" value="Press me."&gt;
  &lt;/form&gt;
  &lt;/p&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>PHP (restart.php):</strong></p>
  
  <pre><code>&lt;?php
  echo "This is a test";
  echo "&lt;br&gt;";
  echo "&lt;br&gt;";
  echo shell_exec('ifconfig');
  echo "&lt;br&gt;";
  echo "&lt;br&gt;";
  echo "Restarting server...";
  exec ('/usr/bin/sudo /etc/init.d/portmap restart');
  shell_exec("/sbin/reboot");
  exec("/sbin/reboot");
  system("/sbin/reboot");
  ?&gt;
  </code></pre>
  
  <p>Mind you that here, I only have so many things attempting to execute, so that I make sure I hit the target when one of them works, if that makes sense. The IFConfig is just a test to make sure that it's actually able to execute.</p>
  
  <p><strong>Sudoers:</strong></p>
  
  <pre><code># User privilege specification
  root    ALL=(ALL:ALL) ALL
  www-data reboot = NOPASSWD: /sbin/reboot
  </code></pre>
  
  <p>This is all on Ubuntu 14.04 LEMP.</p>