Shell-script-php Execution of shell scripts

Source: Internet
Author: User
1. I wrote a php script to execute some shell scripts through the WEB interface. shell script will use sudo3.sudo user has set NOPASSWORD4. manually in the nobody user environment, (su-sbinbashnobody), and then execute shell script can be executed normally ,... 1. I wrote a php script to execute some shell scripts through the WEB interface.

2. sudo is used in shell scripts.

3. The sudo user has set NOPASSWORD

4. in the nobody user environment manually (su-s/bin/bash nobody), you can execute the shell script normally, but with php, The sudo statement will not be executed.

How can I use php for execution? Currently, the shell_exec function is used for execution.

Reply content:

1. I wrote a php script to execute some shell scripts through the WEB interface.

2. sudo is used in shell scripts.

3. The sudo user has set NOPASSWORD

4. in the nobody user environment manually (su-s/bin/bash nobody), you can execute the shell script normally, but with php, The sudo statement will not be executed.

How can I use php for execution? Currently, the shell_exec function is used for execution.

Yes, sudo: sorry, you must have a tty to run sudo

Modify the system configuration.

This is relatively dangerous .... First, no matter how it is implemented...
Sudo, you need sudo to enable the PHP process, so all php Execution is sudo.

Add www users to the root group

2. sudo is used in shell scripts.

This statement means that the execution of shell scripts requires the sudo permission?

It seems that this operation is very dangerous. Exercise caution.

Of course, not execution is generally caused by permission issues. Run the PHP script in the webserver environment. Take nginx as an example. Generally, www users are used. You can run the script in cli.root group.
Second, it is easy to debug. You can try

sudo -Hu www php your.php

And,shell_execThe function returns a value, which is the shell output,err_log()Go to the file.

Php can only execute some commands, that is, use root.

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.