Are there any advice to make php-script run python-script with “exec” function without being a “root” user?
I’m a user of Grove Pi+ on Raspberry Pi3 /w Raspbian OS.
When I call a simple python-script that blinks LED once, from a PHP-script via browser, it gives me a permission error such as below.
Traceback (most recent call last): File "grove_blink.py", line 6, in from grovepi import * File "/var/www/html/grovepi.py", line 64, in bus = smbus.SMBus(1) IOError: [Errno 13] Permission denied
To isolate the problem I ran this PHP-script via command line, and it worked fine.
> pi@raspberrypi:/var/www/html $ php grove_blink.php
Also tried a direct call from PHP command line, and worked fine.
> pi@raspberrypi:/var/www/html $ php -r "exec('python ./grove_blink.py');"
Naturally, if I run the python-script, that the php-script above calls, worked fine too.
> pi@raspberrypi:/var/www/html $ python grove_blink.py
So, I assumed running this php-script via browser causes the problem.
I did some research and I understood that I needed to be a “root” or “pi” user to run, since the apache web server is a “www-data” user. It made sence.
So I called this python script with “sudo”, then I get an error such as below:
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
It seems that I have to give the password but that’s what I don’t want, nor giving a “ALL=NOPASSWD” setting to sudoers.
Also I checked the “/dev/i2c*” permission and the owner was “root” with “i2c” group.
So the next step I took was adding user “www-data” to “i2c” group and “gpio” group.
But it didn’t work.
Are there any advice to make php-script run python-script with “exec” function without being a “root” nor “pi” user?