One of the annoying things about Ubuntu is the fact that you need to be an admin user to shutdown the PC. This makes sense if you are running a server, but not when you have a few PCs scattered throughout the house that you’d just like to shutdown quickly.
So, I found a way to enable this through Apache. Warning: this will allow anyone who browses to your PC to shut it down without prompting. So use carefully.
Basically, what you need to do is remove the need for admin/sudo access when shutting down as the
www-data (Apache) user. To do this, you use a specific command called
visudo which specially edits a file containing what commands require admin access.
In short, make sure that the last line in that file is the following:
www-data ALL= NOPASSWD: SHUTDOWN_CMDS
and that there is a line further up that says
Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/reboot, /sbin/halt.
Then, once this is done, you can have a shutdown.php that has the following code:
<?php echo exec('sudo shutdown -h now'); ?>