[英]Executing sudo shell script by php
i am trying to execute pkill command by php script.我正在尝试通过 php 脚本执行 pkill 命令。
killengine.sh script runs fine from terminal, both with ./killengine.sh and php restart.php. killengine.sh 脚本从终端运行良好,包括 ./killengine.sh 和 php restart.php。
this is killengine.sh这是killengine.sh
#!/bin/bash
sudo pkill -f engine
and this is restart.php这是restart.php
$out = shell_exec("/var/www/killengine.sh 2>&1");
var_dump($out);
Both files have 755 permissions.这两个文件都有 755 权限。 Ownew of restart.php is apache, and root is owner of killengine.sh. restart.php 的所有者是 apache,root 是 killengine.sh 的所有者。 Also i tried with both owners to be root/apache.我也尝试与两个所有者成为 root/apache。
In visudo i made this changes:在 visudo 中,我进行了以下更改:
Defaults:apache !requiretty
but i get: "sudo: no tty present and no askpass program specified"但我得到:“sudo:没有 tty,也没有指定 askpass 程序”
Then i tried with然后我试过
Defaults!/var/www/killengine.sh !requiretty
then i get: "sudo: sorry, you must have a tty to run sudo"然后我得到:“sudo:抱歉,你必须有一个 tty 才能运行 sudo”
Also, this line is present all the time at the EOF此外,这条线一直存在于 EOF
apache ALL=NOPASSWD: /var/www/killengine.sh
but without success.但没有成功。
OS is Centos 6操作系统是 Centos 6
Any ideas?有任何想法吗?
solution:解决方案:
changed restart.php to将 restart.php 更改为
$out= @shell_exec("sudo /var/www/killengine.sh");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.