shell-script-php execution of Shell scripting issues
Source: Internet
Author: User
KeywordsPhpshellshell-scriptshell_exec
1. I wrote a PHP script to execute some shell scripts through the Web interface.
The 2.shell script will use sudo
3.sudo user has set the Nopassword
4. Manually in the nobody User environment, (su-s/bin/bash nobody), and then execute the shell script can be executed normally, but through PHP execution, sudo that statement will not execute
How do I use PHP? This is currently performed using the Shell_exec function.
Reply content:
1. I wrote a PHP script to execute some shell scripts through the Web interface.
The 2.shell script will use sudo
3.sudo user has set the Nopassword
4. Manually in the nobody User environment, (su-s/bin/bash nobody), and then execute the shell script can be executed normally, but through PHP execution, sudo that statement will not execute
How do I use PHP? This is currently performed using the Shell_exec function.
Know the reason, yes, sudo:sorry, you must has a TTY to run sudo
The system configuration can be modified.
This is a relatively dangerous way .... First of all, no matter how to achieve ... sudo you need sudo to open the PHP process so PHP is doing sudo.
Add the WWW user to the root group
The 2.shell script will use sudo
This means that the execution of the shell script requires sudo permission?
It seems that this is a very dangerous operation Ah, cautious and cautious.
Of course, non-execution is generally caused by permissions issues. Execute PHP script in webserver environment, take Nginx as an example, generally use WWW user, you can under the CLI, if based on your request, first www should belong root group . Second, for ease of debugging, you can try the CLI
sudo -Hu www php your.php
Also, the shell_exec function returns a value, that is, the shell's output, err_log() to the file to see the chant.
PHP can only execute part of the command, which is the same with root.
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.