When I call a simple python-script that blinks LED once, from a PHP-script via browser, nothing happens.
and I add these lines in the sudoers file.
apache ALL=(ALL) NOPASSWD: ALL
apache2 ALL=(ALL) NOPASSWD: ALL
www-data ALL=(ALL) NOPASSWD: ALL
adm ALL=(ALL) NOPASSWD: ALL
/var/www/html
owner
&Group
is www-data
and python script owner
&Group
is www-data
also
what is the problem?
<html>
<head>
<?php
if (isset($_POST['RedON']))
{
exec('sudo python /var/www/html/xbee.py');
}
if (isset($_POST['RedOFF']))
{
exec('sudo python /home/pi/xbee2.py');
}
if (isset($_POST['YellowON']))
{
exec('sudo python /var/www/html/xbee2.py');
}
if (isset($_POST['YellowOFF']))
{
exec('sudo python /var/www/gpio/yellow_off.py');
}
if (isset($_POST['GreenON']))
{
exec('sudo python /var/www/gpio/green_on.py');
}
if (isset($_POST['GreenOFF']))
{
exec('sudo python /var/www/gpio/green_off.py');
}
?>
<title></title>
</head>
<body>
<form method="post">
<table
style="width: 75%; text-align: left; margin-left: auto; margin-right: auto;"
border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="text-align: center;">Turn LED on</td>
<td style="text-align: center;">Turn LED off</td>
</tr>
<tr>
<td style="text-align: center;"><button name="RedON">Red On</button></td>
<td style="text-align: center;"><button name="RedOFF">Red Off</button></td>
</tr>
<tr>
<td style="text-align: center;"><button name="YellowON">Yellow On</button></td>
<td style="text-align: center;"><button name="YellowOFF">Yellow Off</button></td>
</tr>
<tr>
<td style="text-align: center;"><button name="GreenON">Green On</button></td>
<td style="text-align: center;"><button name="GreenOFF">Green Off</button></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Not: python script works in SSH Normally.
echo(exec('sudo python /var/www/html/xbee.py 2>&1'));
. – user2027202827 Dec 1 '16 at 4:13echo
the output of your exec statements. That will print anything that your python call returns to the webpage. That only gets you part of the way there though because whatever errors occur are printed tostderr
instead ofstdout
. By adding2>&1
following your python script, that will redirect the output that's meant forstderr
tostdout
so thatecho
can print it. Give that a try and let me know what errors show up. – user2027202827 Dec 1 '16 at 4:18index.html
notindex.php
so it's not running through the interpreter. – calcinai Dec 1 '16 at 16:50