Sign up ×
Server Fault is a question and answer site for 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:


but when I try to run a simple php script:

echo "\nfirst: ";
echo shell_exec("whoami");
echo "\nsecond: ";
echo shell_exec("sudo ls");

I get the results:

first: daemon

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

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

Your Answer


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.