Home:ALL Converter>How to suspend/restart Linux Ubuntu from PHP script?

How to suspend/restart Linux Ubuntu from PHP script?

Ask Time:2013-08-26T15:27:34         Author:Mohammad Moodi

Json Formatter

I have a problem. I want to restart ubuntu with php code but I can not. I have tried all of codes from the internet like

<?php
shell_exec("/usr/sbin/reboot");
exec("/usr/sbin/reboot");
system("/usr/sbin/reboot");
?>

and

<?php
shell_exec("shutdown -r");
exec("shutdown -r");
system("shutdown -r");
?>

But all of them do nothing. Please help me. I need this code.

Author:Mohammad Moodi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18438805/how-to-suspend-restart-linux-ubuntu-from-php-script
Paulo Scardine :

If the PHP code is being executed by the webserver, it is running under the user \"www-data\" in ubuntu.\n\nProbably www-data has no right to shutdown, which is a sane default.\n\nYou can give www-data sudo rights to shutdown without providing a password and call reboot using sudo.\n\nTake a good look at man sudoers and be sure to understand the security implications before editing the sudo config: this will effectively give any PHP script the right to shutdown the server (untested).\n\n# /etc/sudoers (edit using the visudo command)\n\nCmnd_Alias SHUTDOWN = /usr/sbin/shutdown\nCmnd_Alias HALT = /usr/sbin/halt\nCmnd_Alias REBOOT = /usr/sbin/reboot\n\nHost_Alias LOCALHOST = 127.0.0.1\n\nwww-data LOCALHOST = NOPASSWD: SHUTDOWN, HALT, REBOOT\n\n\nIn PHP you can use:\n\nshell_exec(\"/usr/bin/sudo /usr/sbin/reboot\");\n",
2013-08-26T07:42:52
yy