gpt4 book ai didi

php - 使用 PHP 从 Apache 服务器运行 Python 脚本

转载 作者:太空宇宙 更新时间:2023-11-04 10:29:46 24 4
gpt4 key购买 nike

我正在使用 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>&nbsp;
<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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com