1

I want to access my GPIO pins of my raspberry pi from my PHP server

I have the python script that switches on and off the LED lights

How can I run my python script from my php? It gives me no error and it doesn't access the pins

I understand that with sudo the password is required.

Php script:

<?php   
            echo "Query for:";
            echo $gpio;
            exec("sudo python rungpio.py");
?>

https://stackoverflow.com/questions/31811253/execute-python-script-from-php The above link doesn't help much. Kindly help

  • How does it related to Ubuntu? you can run sudo this way: 'echo youPassword | sudo -S yourCommand' (Which is not recommended) – Ravexina Apr 9 '17 at 11:24
1

I understand that with sudo the password is required.

That's not necessarily the case. As the sudoers man page describes, if you put "NOPASSWD:", it doesn't require a password.

For example:

www-data ALL = NOPASSWD: /usr/local/bin/rungpio.py

would allow the user www-data to run /usr/local/bin/rungpio.py with sudo, without requiring a password (please note that it should be executable and start with a shebang, such as #!/usr/bin/env python).

Alternatively, you could change the permissions of the device files so that the user php is running as can modify them, and get rid of sudo. And even change them directly, instead of needing to jump to python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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