0
I am trying to shutdown my RaspberryPi running Raspbian from a php script running on lighttpd webserver.
shell_exec("sudo /sbin/shutdown -h now 2>&1");
I added lighttpd ALL=(ALL) NOPASSWD: /sbin/shutdown
to my /etc/sudoers file and checked that Defaults !requiretty
is set.
I still get "sudo: no tty present and no askpass program specified" when running the script.
Can somebody please help me? Thanks!
I think you may want the
shell_exec
function instead ofexec
since that is a shell command (I think that's how it works). I am not 100% sure (hence the comment), but may be worth a try. – nerdwaller – 2013-04-25T19:33:15.920Output redirection (
2>&1
) requires a shell; try removing that from the command and see if you get a different result. – Aaron Miller – 2013-04-25T20:14:15.197Thanks for your comments. Actually I already tried shell_exec in the first place. I just have copied the wrong command to my question. And exec("sudo /sbin/shutdown -h now"); doesn't work either. – frsc – 2013-04-25T20:34:54.293
Are you sure that lighttpd is running as user lighttpd? In a php script,
echo \
whoami``; It might be www-data or http instead – WJDev – 2013-04-25T20:57:44.927