Running a python script from my php server

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");
?>

The above link doesn't help much. Kindly help

1

1 Answer

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like