I'm running the webserver lighttpd on Raspbian (Debian based) on a Raspberry Pi. The server runs as user www-data (checked with ps aux). I added the following line to /etc/sudoers:www-data ALL=NOPASSWD:/opt/vc/bin/vcgencmdto be able to run the vcgencmd tool from the Raspberry Pi that gives status information from within a PHP file with<? echo shell_exec('vcgencmd version'); ?>All it prints is VCHI initialization failed (instead of the supposed version information that appears when I run it on my user even without sudo) which appears when vcgencmd is run with wrong permissions.Running for example<? echo shell_exec('cat /sys/class/thermal/thermal_zone*/temp'); ?>works fine without any /etc/sudoers change, so there's no problem with PHP (like forbidden shell_exec or something).What else needs to be set in order to execute a command?
Adding www-data to /etc/sudoers dos not work for PHP shell_exec() to run a command
sudo
If you want to use something you added to /etc/sudoers, you have to call sudo.sudo is just a program with the setuid bit set. There's absolutely nothing more special about it, meaning it doesn't interpose itself every time a program is launched.The reason you can call cat /sys/class/thermal/thermal_zone*/temp is because you have read access to those files. Depending on how your filesystem permissions are set, you may have read access, but not necessarily write.The reason vcgencmd version might work when launched as your own user has 2 possible explanations:You have alias vcgencmd='sudo vcgencmd in your profile, thus you automatically run sudo.You have sufficient permissions to the files that vcgencmd needs to operate. If you need write access, and the files are owned by a group you're a member in, and have write access for that group, then you won't need sudo.In summary, either change your command to sudo vcgencmd version. Or find what file permissions you need to modify and modify them.