On Raspberry Pi, php executes the root permission program through sudo.

Source: Internet
Author: User
: This article mainly introduces the program for executing the root permission through sudo on php on Raspberry Pi. if you are interested in the PHP Tutorial, refer to it. 1. problems and causes

The reason why the PHP homepage on Raspberry Pi cannot run commands or scripts with root permissions is not that PHP cannot run,ApacheThe permission is insufficient !!!!

2. PHP method for running shell scripts or Python

Php provides the system (), exec (), passthru () functions to call external commands.
Although these three commands can execute shell commands in linux, they are actually different:

System () outputs and returns the last shell result.
Exec () does not output results. The last shell result is returned. all results can be saved to a returned array.
Passthru () only calls the command and directly outputs the command running result to the standard output device.
Similarities: both of them can obtain the command execution status code.
Example: system ("/usr/local/bin/webalizer ");

3. PHP uses sudo to execute the root command or script

1) open the sudo commandApacheUser permissions.

Modify the sudo permission control file/etc/sudoers file. Raspberry Pi uses the following command:

Sudo nano/etc/s udoers or you can run the following command to edit the/etc/sudoers File: sudo login do

Add the following line: Open all permissions for this user

Www-data ALL = (ALL) NOPASSWD: ALL # MyApacheThe user is www-data.

Or nobody ALL = (ALL) NOPASSWD: ALL # if yourApacheIs the default user, then the user is nobody

You can also add the following content to open the permission for a command:

Nobody ALL = (ALL) NOPASSWD:/usr/local/Apache/Bin/ApacheCt1 restart

2) comment out the Defaults in the file.RequireTty line. otherwise

Sudo: sorry, you must have a tty to run sudo.

3) save the disk and exit

The above describes the programs on Raspberry Pi that execute root permissions through sudo in php, including Apache and require, and hope to help those who are interested in PHP tutorials.

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.