0

I am using exec() to call python script. It return error code 1, but I type it on terminal is okay.

My operating system is Ubuntu 14.04 LTS.

Here is my php exec() content :

exec("sudo python /path/to/python.py --videoId $link", $output, $return);

I use visudo to set www-data can get root.

www-data ALL=(ALL)    NOPASSWD: /path/to/upload.php

Did I miss something have to set or the code is wrong?

user3927463
  • 165
  • 1
  • 2
  • 13
  • Your sudoers file should allow www-data user to run the python script as root, not just the php script. – Oldskool Nov 26 '15 at 15:52
  • The same way you set the PHP script to run as root, with visudo. But then just add `python /opt/SuperBlinder/superYoutuber.py` as well. – Oldskool Nov 26 '15 at 16:09
  • like this? `www-data ALL=(ALL) NOPASSWD: /opt/SuperBlinder/superYoutuber.py` – user3927463 Nov 26 '15 at 16:17
  • No, be sure to add the full path to Python as well. Probably goes for the PHP line as well (unless the scripts are executable by themselves (+x chmod flag)). – Oldskool Nov 26 '15 at 16:23
  • Add `2>&1` to the command line and check the ouput! – hek2mgl Nov 26 '15 at 16:24
  • I add `2>&1`, it return `sudo: no tty present and no askpass program specified`. I am trying to figure out what python version did I use.. There are too many version on this computer. – user3927463 Nov 26 '15 at 16:32

1 Answers1

0

I just simply change

www-data ALL=(ALL)    NOPASSWD: /path/to/upload.php

To

www-data ALL=(ALL)    NOPASSWD: ALL

And it can work. But I think this is not best answer.

user3927463
  • 165
  • 1
  • 2
  • 13