I'm a beginner to Apache2.
What I want to do
・I want to execute a shell script with PHP in apache2 by using raspberry pi 3.
What I did in order to do above.
- I installed apache2 and php7 to my Raspberry pi.
I put
index.php
which was written thathello world
in/var/www/html/
directory.
The scripts is below./var/www/html/index.php
<?php echo('hello world'); ?>
I made sure that I can see
hello world
from the browser in my local PC connected to my raspberry pi.- I changed the PHP script to execute the shell script.
The scripts is below.
/var/www/html/index.php
<?php exec('sh /var/pi/blink.sh'); ?>
error
・Apache2 don't execute the shell script.
try
- I made
www-data
user have the authority to execute it without password.
・$ sudo visudo # => /etc/sudoers.tmp
・I addedwww-data ALL=NOPASSWD:/bin/sh
to the file above. - I made sure that I can run ,by changing the authority,
sh /var/pi/blink.sh
file in raspberry pi which I want to run in Apache2 in raspberry pi . - I added
sudo
toindex.php
which looks like<?php exec('sudo sh /var/pi/blink.sh'); ?>
However, nothing changed.
The devices I'm using
・Mac book air (OSX 10.13.6)
・Raspberry pi (Model B) with Raspbian (Raspbian GNU/Linux 9 (stretch).