The PHP program uses sudo to execute the application

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.