I have a php script that should (I think) run a python script to control the energenie radio controlled plug sockets depending on which button is selected. It seems to work in that it echos back the correct message when the button is pressed but the python scripts don''t appear to run. I have added the line:
www-data ALL=NOPASSWD: /usr/bin/python /home/pi/lampon.py
which should give the apache user privileges to run the python script at least for turning on the power socket but it doesn't work. The script itself does work when run via the pi command line itself. Any suggestions? (the code for the php is below)
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>LED Control</title>
</head>
<body>
LED Control:
<form method="get" action="energenie.php">
<input type="submit" value="ON" name="on">
<input type="submit" value="OFF" name="off">
</form>
<?php
if(isset($_GET['on'])){
shell_exec("python /home/pi/lampon.py");
echo "LED is on";
}
else if(isset($_GET['off'])){
shell_exec("python /home/pi/lampoff.py");
echo "LED is off";
}
?>
</body>
</html>