doudi5524 2015-01-08 17:30
浏览 63

PHP exec()无法在Raspberry apache服务器上运行

I have a Raspberry Pi with an Apache server on it (PHP5). I got a code to control my relay module but PHP does not execute the python script.

This is the code:

<html>
<head>
<meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<?php
if (isset($_POST['LightON']))
{
exec("sudo python /home/pi/lighton_1.py");
}
if (isset($_POST['LightOFF']))
{
exec("sudo python /home/pi/lightoff_1.py");
}
?>
<form method="post">
<button class="btn" name="LightON">Light ON</button>&nbsp;
<button class="btn" name="LightOFF">Light OFF</button><br><br>
</form>
</html>
  • 写回答

2条回答 默认 最新

  • dongmeixian9665 2015-01-08 17:33
    关注

    Look in your php.ini if exec() is enabled. If it isn't, uncomment it and restart your PHP process (and maybe apache too)

    EDIT:
    After submitting an edit I noticed that you use sudo in your PHP exec() statement. This doesn't work if your root user is protected by a password (which it really should!).

    评论

报告相同问题?