Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
2  
Does the user running Apache have rights to execute your runpython.cgi? Do you have CGI enabled? Does the user running Apache have the right to use sudo? (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:00
    
It is almost certainly related to the use of sudo. When you execute the program (with sudo) through the shell, you have to type in the password, right? How is the Apache user (probably www-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

1 Answer 1

Take a look at mod_wsgi: https://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

Also, are you sure your script needs to run as root?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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