Restarting a Linux Server via Web Browser (PHP) Restarting a Linux Server via Web Browser (PHP) linux linux

Restarting a Linux Server via Web Browser (PHP)


You can do this either by editing your sudoers file :

Sudoers:

www-data ALL=(root) NOPASSWD: /sbin/reboot 

The first ALL is for the hostname if you're hostname is not 'reboot' I advise you to keep ALL as it will work in any hostname. That's why it doesn't seem to work on your server

restart.php

exec('sudo /sbin/reboot');

Or without editing your sudoers file.

  • First create a file where you're gonna store you're root password

~/password :

myrootpassword
  • Second run any command you want while being root from php file (don't forget to specify the file which store your password)

phpfile.php :

exec('sudo -u root -S /sbin/reboot < ~/password');


 www-data reboot = NOPASSWD: /sbin/reboot

this means you dont need a password when running sudo, not that the command runs as sudo when ever run by that user.

The answer is to use sudo /sbin/reboot as the command


You can use puty. I think using php is not a good plan.