0

I am wanting to restart a python script from PHP.

I have created the shell script:

# kill script
`which pkill` -f "$script"

# start script
`which python` "$script" > /dev/null &

when I execute this with www-data (PHP [shell_exec()]) I get the error:

/usr/bin/python: can't open file '$script': [Errno 13] Permission denied

and the permissions of the '$script' is:

-rwxrwxrwx 1 www-data www-data

The script is not in /var/www and nor do I want it to be.

maxisme
  • 3,974
  • 9
  • 47
  • 97
  • Have you checked the permissions on the directory where `$script` is stored? User www-data will need to have 'x' permission in order to see what is inside the directory. – Craig Dec 20 '17 at 15:38
  • @yivi it is not clear what you are saying is not clear? – maxisme Dec 20 '17 at 16:28
  • @Craig parent directory: `drwxr-xr-x 2 www-data www-data` – maxisme Dec 20 '17 at 16:28
  • You tagged this question PHP and Python. there is no PHP nor Python code in this question. – yivi Dec 20 '17 at 16:29
  • Both php and python are used in my code as applications. – maxisme Dec 20 '17 at 16:30
  • `which python` is used in my question as well as "I execute this with www-data (PHP)" – maxisme Dec 20 '17 at 16:31
  • Your question doesn't include PHP nor Python code. It shoulnd't be tagged with those languages tags... Can't be any more clearer than that. Either relevant code is missing, or the wrong tags are being used. – yivi Dec 20 '17 at 16:32
  • well that is not true. – maxisme Dec 20 '17 at 16:34
  • top 10 most famous php question -> https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api can't see php – maxisme Dec 20 '17 at 16:34
  • that's a seven years old question. the standards have changed **considerably** – yivi Dec 20 '17 at 16:35
  • You should read this: https://stackoverflow.com/help/tagging. I'm not attacking you, just trying to help. – yivi Dec 20 '17 at 16:36
  • Again, there is no PHP. No PHP expert can help you with this question as stated. There is no reason to tag this question as PHP. – yivi Dec 20 '17 at 16:39

1 Answers1

-1

My solution was to allow root (sudo) to python by adding this to visudo:

www-data ALL = (root) NOPASSWD: /usr/bin/python
maxisme
  • 3,974
  • 9
  • 47
  • 97