I am trying to set up some PHP scripts that will turn on/off a daemon (fatcontroller for some AWS SQS processing) via /etc/init.d/. Turnkey appliances seem to come without suod installed, so I ran a simple apt-get install sudo.
When I just use the php function:
Ok, this makes sense... the Apache www-data user doesn't have permissions to start/stop daemons. So I read about how you can give the password to the sudo command using a pipe (http://stackoverflow.com/questions/11955298/use-sudo-with-password-as-parameter), and I tried this:
exec('echo password | sudo /etc/init.d/fatcontrollerd start');
This doesn't return anything (usually exec returns output of the command)... so I tried running the same command via a terminal window after doing su www-data to see exactly what's happning. This is the output I get:
So... it looks like for whatever reason whenever I try to sudo as the www-data user, sudo appears to be trying to run the command as www-data instead of root? I tried providing sudo the -u option to force the user I'm trying to access when running sudo, but the prompt keeps asking for the www-data user password!
This issue is complicated because the Turnkey appliances do NOT come with sudo installed, so I am not entirely sure I haven't missed some important step that was required after running apt-get install sudo.
Thanks for any help you can provide!