In the Raspberry Pi using PHP to execute the already written C program to obtain some hardware information, because to operate GPIO, so you must use sudo to execute the program.
But it's no problem to execute it directly inside bash, and there's no input in PHP.
I made an implementation, with the simplest LS command, direct exec ("LS/") can get the data, but after adding sudo, exec ("sudo ls/") will not have any output.
So basically it can be concluded that PHP permissions are a problem.
Because PHP is dependent on Apache to run, so the permissions problem of PHP back to the Apache permissions problem.
View Apache execution users on Raspberry Pi:
PS AUXFWW | grep ' httpd '
The discovery is performed with the default User pi, and the sudo visudo command can see that the PI user can use sudo directly to execute any program without entering a password. That's weird.
Looking back at the examination, the logic is right AH. But PHP never does.
So directly PS Auxfww, see httpd really have pi to carry out, but in addition to httpd this process, there is Apache process.
PS AUXFWW | grep ' Apache '
found that the user executing Apache is www-data, and there is another nobody
Add these 2 to the Super user group via sudo visudo and restart Apache
Www-data all= (All) Nopasswd:all nobody all= (all) Nopasswd:all sudo/etc/init.d/apache2 restart
I can do it.
The PHP program uses sudo to execute the application