我正在使用 raspberry pi 进行一个项目,以使用移动设备打开和关闭 LED 灯条。
我遇到的最后一个问题是让脚本从托管在树莓派上的 apache 服务器运行。
<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.py");
}
if (isset($_POST['LightOFF'])) {
exec("sudo python /home/pi/lightOff.py");
}
?>
<form method="post">
<button class="btn" name="LightON">Light ON</button>
<button class="btn" name="LightOFF">Light OFF</button><br><br>
</form>
</html>
Python 脚本在 raspberry pi 上的命令行运行时完美运行。但是在 apache 服务器上运行时,什么也没有发生。我在这里做错了什么?跟权限有关系吗?我是 linux 和 php 的新手,请记住这一点。
为什么 Python 在本地运行而在服务器上运行不正常?
谢谢!
最佳答案
对于偶然发现此问题的任何人,只需在文件路径前添加 sudo
即可解决问题。
关于php - 使用 PHP 从 Apache 服务器运行 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40498208/