1

i'm running Nginx on my Raspberry PI with PHP 5.4.14 (fpm-fcgi). It all works well. But in one script i make a shell call using shell_exec.

echo shell_exec("sudo python " . $file);

it works well if i use the console with

php test.php

but if i use the browser to call this file the php-file will be executed but i don't get any output by the shell_exec (not even an error message).

So i hope you could help me fix this problem.

The called python file makes use of the GPIO so sudo is required, right?

Here is my python code:

#!/usr/bin/env python
try:
    import RPi.GPIO as GPIO
except RuntimeError:
    print "Error Importing GPIO. Did your forgot the superuser privilieges?"

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

GPIO.setup(3, GPIO.OUT)

GPIO.output(3, not GPIO.input(3))

print "New LED state is: ", GPIO.input(3)

#GPIO.cleanup()

2 Answers 2

2

for future reference:

I found a - i my eyes - not really nice solution:

sudo echo "apache ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

Found here.

Sign up to request clarification or add additional context in comments.

Comments

0

Mm, i have try with this two simple example:

/Scripts/test.py

#!/usr/bin/env python
print (str('hello world'))

/var/www/test.php

<?php
echo shell_exec('/Scripts/test.py');
?>

via a browser, show me "hello world"

Perhaps try this:

chmod a+x your_py_file.py

Hope that help..

2 Comments

i will test this, as soon as i'm back home. But still i'm missing a sudo there. Or is it not needed?
so after the chmod i at least got an error message. "Error Importing GPIO. Did you forgot the superuser privilieges?" this means i still have the problem with the missing sudo, due to the GPIO. I added the python code to the question above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.