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

标签 php python linux apache raspberry-pi

我有一个 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>&nbsp;
<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/

相关文章:

linux - sed 因错误而失败

PHP/MYSQL - 一个查询中的多个表

php - 使用 session_register_shutdown() 的目的是什么?

php - 如果文件存在则添加数字 PHP

python - 使用包含单引号的 json 更新 PostgreSQL 中的 jsonb 字段

php - 搜索引擎的困境

php - Javascript Span 作为 PHP 变量

python - Python 中推荐的缩进大小是多少?

c - 前置子进程控制台输出

python - 有没有办法在Linux中通过Python启用tor作为系统代理设置