简体   繁体   English

Raspberry Pi无法通过PHP执行脚本

[英]Raspberry Pi unable to execute script by PHP

I'm playing with Raspberry Pi and anm Arduino shield in order to run a script via Apache / PHP . 我正在玩Raspberry Pi和Arduino ,以便通过Apache / PHP运行脚本。 This script simple blink a LED . 该脚本简单地使LED闪烁。 I have already tested the script via shell and it works fine, with the command 我已经通过shell测试了脚本,并且可以使用以下命令正常工作

/root/arduPi/blink_test

I'm able to see my LED blinking. 我能够看到我的LED闪烁。 So I made the same thing via Apache PHP with this short PHP script 所以我用这个简短的PHP脚本通过Apache PHP做了同样的事情

<?php
    if(isset($_GET['cmd'])){
        echo '/root/arduPi/'.$_GET['cmd'];
        exec('/root/arduPi/'.$_GET['cmd']);
    }
?>

but nothing happen and no error has been displayed. 但没有任何反应,也没有显示错误。

I tested the PHP code with 我测试了PHP代码

<?php
    phpinfo();
?>

and it's fine. 很好 How can I fix this problem? 我该如何解决这个问题?

I had the same issue a while back it was because Apache does not have permission to access certain devices on the Pi. 前一段时间我遇到了同样的问题,这是因为Apache没有权限访问Pi上的某些设备。 I fixed this by getting rid of the need to be root to access these devices. 我通过消除root用户访问这些设备的需要来解决此问题。 HERE Is my post about this same issue the fix was to setup sudo as passwordless. 在这里,我的帖子是关于同一问题的,修复是将sudo设置为无密码。 THIS is what I used to accomplish setting up sudo as passwordless. 就是我用来完成将sudo设置为无密码的过程。 You should then be able to execute the script as follows exec('sudo /root/arduPi/'.$_GET['cmd']); 然后,您应该能够执行脚本,如下所示: exec('sudo /root/arduPi/'.$_GET['cmd']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM