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');