Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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