【发布时间】:2019-04-29 20:23:31
【问题描述】:
我是 Apache2 的初学者。
我想做什么
·我想在apache2中使用树莓派3执行一个shell脚本。
为了达到上述目的,我做了什么。
- 我在树莓派上安装了 apache2 和 php7。
-
我把
index.php写成hello world放在/var/www/html/目录中。
脚本如下。/var/www/html/index.php
<?php echo('hello world'); ?> 我确保可以从连接到树莓派的本地 PC 的浏览器中看到
hello world。- 我更改了 PHP 脚本以执行 shell 脚本。
脚本如下。
/var/www/html/index.php
<?php exec('sh /var/pi/blink.sh'); ?>
错误
・Apache2 不执行 shell 脚本。
试试
- 我让
www-data用户有权在没有密码的情况下执行它。
・$ sudo visudo # => /etc/sudoers.tmp
·我在上面的文件中添加了www-data ALL=NOPASSWD:/bin/sh。
- 我确保我可以通过更改权限来运行树莓派中的
sh /var/pi/blink.sh文件,我想在树莓派的 Apache2 中运行该文件。
- 我将
sudo添加到index.php,看起来像<?php exec('sudo sh /var/pi/blink.sh'); ?>
然而,一切都没有改变。
我正在使用的设备
・Mac book air (OSX 10.13.6)
・Raspberry pi (Model B) with Raspbian (Raspbian GNU/Linux 9 (stretch)。
【问题讨论】:
标签: php linux apache shell raspberry-pi