I want to use php or jquery to control gpio pins on my raspberry pi 2. I have apache installed. When i execute python files using LXTerminal, they work fine. I have made the .py files executable and added www-data to sudoers file.
This is the php code:
<html>
<head>
<?php
if (isset($_POST['ON']))
{
exec('sudo python var/www/gpio/on.py');
}
if (isset($_POST['OFF']))
{
exec('sudo python var/www/gpio/off.py');
}
?>
</head>
<body>
<form method="post">
<button name="ON">LED On</button>
<button name="OFF">LED Off</button>
</form>
</body>
</html>
python script
#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)
What's the mistake?
sudoers
etc. are better off on our larger sibling site Unix & Linux. General programming belongs on Stack Overflow.