1

I have an apache web server installed in my Raspberry Pi. I created an index.php file on the /var/www/html folder. Whenever I access my Pi's IP address on a web browser to control the lights, none of my commands seem to work after I press the buttons.

My index.php file is as follows:

<html>
<head>
<?php

shell_exec("gpio -g  mode 4 out");

$btn1 = exec('gpio -g read 4');


if(isset($_POST['l1'])) {
    if($btn1 == 1) {
        shell_exec("gpio -g write 4 0");
    }
    else {
        shell_exec("gpio -g write 4 1");
    }
}
?>

<title> LIGHT DEMO CONTROLS</title>
</head>

<body style= "background-color: rgb(0,44,165);" align = "center"><br><font size = "10" face = "Segoe UI" color = "white"><center>
LIGHT CONTROLS<br> <LIGHT CONTROLS<br>--</center></font><br><form method = "post">
    <table style = "width:600px; margin-left: auto; 
    margin-right: auto;margin-top: auto; margin-bottom: auto;"
    border = "2" cellpadding = "2" cellspacing = "2">
    <tbody>
<tr style = "text-align: center;">
    <td style = "text-align: center;"><font size = "10" face = "Segoe UI" color = "white"> L I G H T S</font></td>
</tr>
<tr>
<td>
<table style = "text-alight: center; margin-left: auto; margin-right: auto;" 
border = "0" cellpadding = "10" cellspacing = "2">
<tbody>
<tr style = "text-align: center;">
    <td style = "text-align: center;"> <font size = "6" face =  "Segoe UI" color = "white"> Light 1</font></td>
    <td style = "text-align: center;"><button style =   "height:100px;width:150px" name= "l1"><font size ="6" face  = "Segoe UI" color = "black"> On/Off </font></button></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
</body>

</html>
  • Basics: did you install the php module for apache? Then, does /var/log/apache2/error.log say anything when you go to your web page? – eftshift0 Aug 1 '18 at 16:35

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.