Use sudo to solve the php shell script execution permission problem

Source: Internet
Author: User
In the past, sudo was basically not used to log on and operate as a root user every time on a virtual machine. However, the recent project needs to do this: access the php Webpage through a browser, php Web pages call and execute a script in linux. This is simple, but in practice, I find that

In the past, sudo was basically not used to log on and operate as a root user every time on a virtual machine. However, the recent project needs to do this: access the php Webpage through a browser, php Web pages call and execute a script in linux. This is simple, but in practice, I find that

Sudo is basically not used to log on and perform operations as a root user every time on a virtual machine. However, you need to perform the following operations in recent projects:PassThe browser accesses the php webpage, which is called in the php webpage.RunIn linuxScript. This is simple, but I found thatPassWhen accessing the browser,ScriptAre notRunAnd I am in the terminalPassCommand LineRunPhp web page does not have anyProblemAt that time, I felt very different. Later I thought about it carefully,PassBrowser access and direct access to the terminalRunThe initiators are different.PermissionOfProblemSo I checked it online, and the result was sudo. Okay, I 've talked a bunch of nonsense. Next I will introduce how to use sudo.SolutionThe abovePermissionProblem.

1. Introduction to sudo

Sudo allows the root user to assign some permissions that are not available to common users, so that common users can also have relevant root users.Permission(For example, sudo can assign some specific commands to a user.RunPermission).

Among them, an important sudo file is/etc/sudoers, which users have what commands canRunIt depends on this file, and sudo can be used only by the user allocated in it.

Sudo-l list the capabilities of this userRunCommand sudo-u user to specify the userRunRun the sudo-k Command to check the time on the admission ticket. The next time you use sudo, enter the password sudo-B in the background.RunCommand
Enter mongodo in the terminal to open the/etc/sudoers file.

Found

In the figure, the content in the red box is added by myself. daemon is a php running user, and the default name varies in different environments, I use daemon in fedora 9, but not in unbuntu.

You can view php running users.PassThe following php web page is obtained.

 

As shown in the figure, each row has three "ALL". The first "ALL" indicates the host in the network, the second "ALL" indicates the target user, and the second "ALL" indicates the identity of the target user.RunCommand, the last ALL representsRunCommand name (you can specifyRunCommand ).

NOPASSWD indicates that no password is required. (For convenience, otherwise IPassIs it too much trouble to enter the password in the program for browser access and wait for feedback)

If it is Ubuntu, you do not need to modify it any more. If it is fedora, you still need to make some modifications,

Defaults env_reset is enabled (that is, remove the # above)

2. Check whether the security mode is enabled in the php. ini configuration file.

Safe_mode = off.

PhpRunLinuxScriptThere are multiple functions, such as shell_exec () and system (). We will not introduce them here. Just use them. I will use the system () function.

Route. php

 

After the preceding settings are complete, RunThe browser will display the setting is successful. ScriptSuccessful Run.

The above is an article written by someone else on the Internet. I did not move around and found some places that I think are inappropriate.

1. phpRunShell is actually used by Apache or Nginx usersRunPhp itself does not create users.

2. Paths involved in php codeProblemThe above code is not standardized. view my other article

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.