I am trying to call a python script from PHP but not having any luck. I have searched for hours but found nothing. The python script is running just fine when I call it from the command line(connected to a relay switch, just runs through them, turning them on and off) and it works just fine. However, I can't seem to figure out how to get it to run from PHP. I am very new to PHP but here is what I am using:
<!doctype html>
<head>
<meta charset="UTF-8"/>
</head>
<?php
if(isset($_POST['switch'])){
exec("sudo python /home/pi/Desktop/test.py");
}
?>
<form method="post">
<button name="switch">Switch</button>
</form>
</html>
What am I doing wrong? I can't seem to find an answer anywhere that will make it work. The PHP is displaying the button just fine, but it does nothing when I click it.