I am trying to grant php sudo access (for automated share mounting). I was sucess full at granting php sudo access on one of my systems by adding daemond to the list of sudo's via

su --login -c 'visudo'

so now it contains the daemond like:

daemon  ALL=(ALL)  NOPASSWD: ALL

but when I try to run a simple php script:

<?php
echo "\nfirst: ";
echo shell_exec("whoami");
echo "\nsecond: ";
echo shell_exec("sudo ls");
?>

I get the results:

first: daemon
second:

That is any time I us shell_exec with sudo in the command nothing is returned or excited. How can I grant php sudo access.

link|improve this question

feedback

1 Answer

up vote 1 down vote accepted

Check your web server error log... I bet you are getting an error like:

# tail -1 /var/log/httpd/error_log
sudo: sorry, you must have a tty to run sudo

If this is the case, try modifying your sudoers file and change/remove the requiretty line:

# grep requiretty /etc/sudoers
Defaults    requiretty

On the other hand, if you are simply trying to automatically mount and share something, autofs/automount might be worth investigating.

link|improve this answer
+1 for the autofs recommendation. Great stuff, and very under-utilized IMO. – ErikA Sep 2 '10 at 19:45
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.