【发布时间】:2013-07-26 06:42:30
【问题描述】:
我想使用由php 执行的shell 脚本更改目录的权限,因此它在apache 用户下运行。
不幸的是,有些目录的权限设置为root。
有没有办法以root 运行此脚本,或者我可以考虑其他替代方案吗?
【问题讨论】:
标签: php php shell permissions root
我想使用由php 执行的shell 脚本更改目录的权限,因此它在apache 用户下运行。
不幸的是,有些目录的权限设置为root。
有没有办法以root 运行此脚本,或者我可以考虑其他替代方案吗?
【问题讨论】:
标签: php php shell permissions root
您正在寻找名为 sudo: https://en.wikipedia.org/wiki/Sudo 的工具,但最有可能的是,您应该重新考虑您的应用架构,而不是使用 sudo,因为一旦您的 httpd 受到攻击,攻击者就可以轻松获得 root 权限。
【讨论】:
我最近发布了一个项目,它允许 PHP 获取真实的 Bash shell 并与之交互。在这里获取:https://github.com/merlinthemagic/MTS
下载后您只需使用以下代码:
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1 = $shell->exeCmd("/path/to/script");
//the return will be a string containing the return of the script
echo $return1;
或者您可以简单地绕过脚本,直接在 PHP 中通过 shell 发出原始命令。这种方法将允许您处理异常。
【讨论】: