Cannot execute python script from php

solvable

Before writing a new question, I am looking for a solution all over the Internet. I have raspberry pi with apache2, php5.4, ssl. I want to execute a python script with php one. The PHP script is located inside / var / www, which has a resolution of 777. Php file:

shell_exec('python /home/pi/Desktop/Python/prova.py'); 

Prova.py has 750 permissions, but its owner is www-data, which is a user printed by shell_exec ("whoami"); which is working. Prova.py:

 print "Hello World" 

The script works directly from the command line:

 php filename.php 

This does not work with broswer!

Finally, I managed to execute the script from the browser. I had to add the www-data user to the sudoers file with my corresponding permission:

 www-data ALL=(ALL) NOPASSWD: /etc/bin/python 
+4
source share
1 answer

Your problem is this: When you run the PHP script through the console, you run php with the permissions of your current user. When a process is executed by opening it in a browser, it will have the user rights of your web process server.

Your group permissions should be 7 no matter what. Either change the permissions of the python scripts to 777 (read-write-execute for everyone), or change it to 770 and make sure that the user of your web servers is inside the group installed in the file.

+3
source

Source: https://habr.com/ru/post/1501214/


All Articles