I am trying to come up with a way to run a python file on my raspberry pi through apache.
To run the program in ssh i type sudo python testfile.py
I have tried through php using exec('sudo python /home/pi/python/testfile.py')
but no joy, i get an error in my /var/log/apache2/error.log
PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
PHP Fatal error: Unknown: Failed opening required '/var/www/index2.php' (include_path='.:/usr/share/php:/usr/$
I have tried using cgi also. but get this error :
(13)Permission denied: exec of '/usr/lib/cgi-bin/runpython.cgi' failed
Premature end of script headers: runpython.cgi
I have googled as much as I can, and checked here to see if I could find anything.
Can anyone offer some help/advice ? Thanks
runpython.cgi
? Do you have CGI enabled? Does the user running Apache have the right to usesudo
? (By the way, don't do that.) What about this/var/www/index2.php
? Anything important there? What is that Python script? Are you trying to build a web application backed by Python or is it a shell script that you wish to execute via a web interface? – Carsten May 15 at 19:00sudo
. When you execute the program (withsudo
) through the shell, you have to type in the password, right? How is the Apache user (probablywww-data
) going to do that? There are ways around this, but you're going to be opening up a can of worms related to security. – Kryten May 15 at 19:23