I run Raspbian Wheezy on my Raspberry Pi, and i want to call a Python script from PHP. That all works great (i call 'exec python go.py' from php) but now i want to call a script which needs root rights.

I understood that running as root would help me out here ('exec sudo python go2.py', so i added this line of code to my sudo file


ok, and now it works again. But then i learned that it is not a good idea to grant the www-data group unlimited sudo rights. Then i found this question (How to grant sudo rights only to specific script files?), which showed me how to grant sudo rights to a single directory:

%www-data ALL=(ALL) NOPASSWD: /var/www/exec/

And then it all stops, because that doesn't work at my machine.

Can you tell me what i'm doing wrong?

i'm using lighttpd as my webserver.

closed as off topic by Sven, mdpc, mailq, Ward, Khaled Feb 27 '13 at 7:42

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

  • huh, why the -1, tell me, i might learn. – Michel Feb 26 '13 at 7:48
  • 1
    This is off-topic here (see the FAQ). It might fit on Unix & Linux or Raspberry Pi, but check their FAQ and archives first. – Sven Feb 26 '13 at 7:58
  • Ah, ok, didn't read the FAQ, thought it was for all kind of server related questions, not only for professionals. Didn't know about the Unix and Linux group, will try it there next time. The raspberry pi group off course was my first choice, but i thought this was more linux specific than Pi specific. – Michel Feb 26 '13 at 8:12

The command you need to run with sudo is python, not exec, so try this:

%www-data ALL=(ALL) NOPASSWD: /usr/bin/python /path/to/the/go2.py
  • Ok, looks like i misunderstood things. I thought the /var/www/exec/ part of my command stated that i allowed sudo rights for the group on the DIRECTORY /var/www/exec/. Is that not a correct assumption? – Michel Feb 26 '13 at 7:59
  • How should i read your proposed line ie what does this part /usr/bin/python /path/to/the/go2.py mean? Is it the combination of the path to a program and the path to the file here, so does it say "Yo can SUDO for python, for the file '/path/to/the/go2.py'? – Michel Feb 26 '13 at 8:01
  • About the first comment: No, %www-data ALL=(ALL) NOPASSWD: /var/www/exec/ allows all users in www-data group to run all commands in the /var/www/exec/ as sudo without prompting for password. About the second: yes. – quanta Feb 26 '13 at 8:05
  • Will try it, will let you know wether it works – Michel Feb 26 '13 at 8:13
  • Hi, i ended up with this %www-data ALL=(ALL) NOPASSWD: /usr/bin/python /path/to/the/* when i only typed the filename it didn't work. i checked it, and a .py file in the /path/to/ directory wasn't executed, and one in the /path/to/the/ folder was. Does that sound logical, the wild card character being necessary? – Michel Feb 27 '13 at 8:55

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