0

On a Raspberry 5, I execute the following php code

$id = 0;
$message = exec("/home/pi/Python/hps_get_voltage_fraction_from_mcp3008.py ".$id." 2>&1");
return $message;

I get the following response:

sh: 1: /home/pi/Python/hps_get_voltage_fraction_from_mcp3008.py: Permission denied

The ownership/permissions are set as follows:

pi@raspberrypi:~/Python $ ls -l
total 4
-rwxrwxrwx 1 www-data www-data 372 Dec  2 18:18 hps_get_voltage_fraction_from_mcp3008.py

The whoami

return exec('whoami');

responds with:

www-data

I tried changing ownership of the script; all to no avail. I also tried executing through sudo, but I get prompted for a password when I exec(sudo...).

Platform info:

pi@raspberrypi:~/Python $ cat  /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
4
  • Have you see this? stackoverflow.com/q/32119703/231316 Commented Dec 3, 2024 at 23:05
  • Also, don't mess around with sudo in an exec or similar context, especially on the web, even if this is just some internal project. Commented Dec 3, 2024 at 23:06
  • Thanks Chris, I did look at it. Did not seem applicable. But now, it appears that the permissions in the /home/pi directory were indeed the problem. Thanks. Commented Dec 4, 2024 at 0:39
  • Try execute your command directly in the console sudo -u www-data you-python-command Commented Dec 4, 2024 at 1:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.