1

led.py

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(7,GPIO.OUT)
GPIO.output(7,1)
time.sleep(5)
GPIO.output(7,0)
GPIO.cleanup()

index.html: (these 2 files are located in /var/www/html)

<?php
        if(isset($_GET['on']))
{
                echo "on";
                exec("sudo python /var/www/html/led.py");
        }
        else if(isset($_GET['off'])){
                echo "off";
        }
?>
<html>
        <head>

        </head>
        <body>
                <form method="get">
                        <button name="on">on</button><br>
                        <button name="off">off</button><br>
                </form>
        </body>
</html>

I have tried system instead of exec. I have added in etc/sudoers these 3 lines

pi ALL=(ALL) NOPASSWD: ALL
www-data ALL=(ALL) NOPASSWD:ALL
%www-data ALL=(ALL) NOPASSWD: /usr/bin/python /var/www/html/led.py

How can i fix this problem ?

  • Have you tried to enable debugging? What do the logs say? Did you really put www-data in the sudoers group? That seems dangerous... – Jacobm001 Feb 13 '17 at 19:06
  • Also, your echo command is missing a ;. – Jacobm001 Feb 13 '17 at 19:07
  • hello jocobm001 i put a ; but still its not working , it isnt calling led.py how can i debug the pi ? – Hilal Feb 14 '17 at 9:56
  • See this question on stackoverflow. In addition, the logs under /var/log/apache2 should tell you something. – Jacobm001 Feb 14 '17 at 16:19
  • thx for your help – Hilal Feb 14 '17 at 18:37

Your Answer

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

Browse other questions tagged or ask your own question.