我有一个 Raspberry Pi,上面有一个 Apache 服务器 (PHP5)。我有一个代码来控制我的中继模块,但 PHP 不执行 python 脚本。
这是代码:
<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>
<button class="btn" name="LightOFF">Light OFF</button><br><br>
</form>
</html>
最佳答案
查看您的php.ini
是否启用了exec()
。如果不是,请取消注释并重新启动 PHP 进程(也许还有 apache)
编辑:
提交编辑后,我注意到您在 PHP exec()
语句中使用了 sudo
。如果您的 root 用户受密码保护(确实应该如此!),则此操作不起作用。
关于PHP exec() 无法在 Raspberry apache 服务器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27846099/