简体   繁体   English

尽管具有sudo权限,PHP exec sudo脚本仍无法运行

[英]PHP exec sudo script not working despite having sudo rights

My php script: 我的PHP脚本:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


exec('sudo /path/to/script.sh');
?>

my visudo line 我的视线

www-data        ALL=NOPASSWD: /path/to/script.sh

(I tripled checked every path) (我检查了每条路径的三倍)

If i remove the 'sudo' in the exec() it will execute (i put a touch aaa at the start, with sudo the file isn't even created so the script doesn't even begin to execute). 如果我在exec()中删除了'sudo',它将执行(我在开始处放了touch aaa ,使用sudo甚至没有创建文件,因此脚本甚至都没有开始执行)。 The script has exec rights for everyone. 该脚本具有所有人的执行权限。

I can't manage to get any error output. 我无法获得任何错误输出。 I can't su into www-data to try to launch it manually with sudo (when I su I get "This account is currently not available. ", but I guess that's normal behavior). 我无法进入www-data尝试使用sudo手动启动它(当我进入su时收到“此帐户当前不可用。”,但我想这是正常现象)。

  1. If your system has selinux or some other policy-based access control engine enabled, your web server process will be running under a constrained context which limits rights further. 如果您的系统启用了selinux或其他基于策略的访问控制引擎,则您的Web服务器进程将在受限的上下文中运行,这进一步限制了权限。 Verify whether you have selinux enabled. 验证是否已启用selinux。

  2. Provide the full path to sudo . 提供sudo的完整路径。 While your shell may have it in its path, perhaps your web server does not. 虽然您的外壳可能在其路径中,但您的Web服务器却没有。

1 -If you're working with RHEL/CentOS and the path is under the /root path you can't execute it. 1-如果您正在使用RHEL / CentOS,并且该路径在/ root路径下,则无法执行它。
2 - Check if the scrit have the 'x' flag (chmod +x /path/to/script.sh) 2-检查scrit是否具有'x'标志(chmod + x /path/to/script.sh)
3 - Check if the user ww-data can execute the scrit with 3-检查用户ww-data是否可以使用以下命令执行scrit

sudo -u www-data script.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM