LuAn Posted July 1, 2007 Share Posted July 1, 2007 I want to run a couple of linux commands from within PHP but they need root access to run them. The following code works and tells me that I am 'apache': [pre]$output = exec('/usr/bin/whoami');[/pre] The following code does not work and $output is empty: [pre]$output = exec('/usr/bin/sudo /usr/bin/whoami');[/pre] I have added the following line to /etc/sudoers [pre]apache ALL = (root) NOPASSWD: /usr/bin/whoami[/pre] I'm on Fedora Core 6 but selinux is set to permissive so it's not that. I've spent the last 6 hours scouring the web for an answer but everything that I'm seeing tells me that what I've done is the way to do it. Any ideas what I'm doing wrong? Quote Link to comment Share on other sites More sharing options...
LuAn Posted July 1, 2007 Author Share Posted July 1, 2007 I just nailed this. The breakthough came when I tried: [PRE]$output = exec('/usr/bin/sudo /usr/bin/whoami 2>&1');[/PRE] The result should be 'root' but what I got, courtesy of the bit on the end, was this: 'sudo: sorry, you must have a tty to run sudo' A search on that told me that the issue related to a setting in /etc/sudoers which is used in Fedora Core 6 namely: [PRE]Defaults requiretty[/PRE] Apparenly FC6 is the only OS that has that setting (which explains why I was struggling to find any information about what was causing the problem). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.