I would like to execute a php script in a browser that will in turn execute a single linux command and return its output. When I first decided to test this out I created this:
<?php $command = "ls"; exec($command, $output); print_r($output); ?>
That worked just fine. But when I changed $command to the command I really wanted to run:
$command = "/etc/init.d/mycontrollerd status /etc/mycontrollerconfig";
it gave me this output:
Array (  => You need root privileges to run this script )
I have been advised to use suexec. However after examining the man page I can't even tell where to begin. Of course I don't want to create a security risk. So can someone give me the recipe to make my command run and return its output?
BTW, this is on a basic LAMP box running Ubuntu.
EDIT: @womlbe below recommends sudo over suexec. With security still being paramount, how could I do this?