Based on http://benaiah41.wordpress.com/2008/08/15/37/
Finally, I add "mylogin ALL = (ALL) ALL" in /etc/sudoers files to solve and allow
sudo for reboot my server successfully on linux shell command from mylogin account
like this firstname.lastname@example.org[~/home/
l/php/] echo "PASSWORD" | sudo -u root -S reboot
So now I try to put the reboot command on php as follow code and it works just only on linux shell after login putty program on my home PC with username=mylogin and my server is rebooting successfully when I type php rb.php
Anyway It does NOT work on browser on my home PC and cron-job on my server.
The php script is for user to reboot the server if they know the root password
from browser or his cronjob scheduler.
I have changed the shell_exec function to exec or system() in php, all doesn't work
on brower or cron-job but all works on the linux shell(putty) executing the php script.
Any idea, sudoers file seems is no issue at all since I 've already add mylogin account name and liunx command with echo "PASSWORD" | sudo -u root -S reboot is working fine.
And it also NOT work if I put it in cron-job like
0 6 * * * echo "PASSWORD" | sudo -u root -S reboot
0 6 * * * php rb.php
So why it is only working on linux shell command and linux shell php script run but NOT work for php script run on browser or cron-job for the same reboot command echo "PASSWORD" | sudo -u root -S reboot ?
And I already change mode(chmod) to 777for rb.php file
$today = date("F j, Y, g:i:s a");
echo $today." Starting rb====\n";
file_put_contents("rb.log",$today." Starting rb====\n");
shell_exec('echo "PASSWORD"|sudo -u root -S reboot');