To execute a shell command from php, typically do the following;
<?php
$output = shell_exec('sudo -u root monit summary');
echo "<pre>$output</pre>";
?>
In the above scenario, we want to run something as root, so we need to modify our /etc/sudoers file;
Firstly, assuming the user is www-data then we can add the following line to /etc/sudoers
www-data ALL = NOPASSWD: /usr/sbin/monit
where /usr/sbin/monit is the command that we wish to allow the user www-data to run without the need to enter a password.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.