【发布时间】:2011-10-04 21:07:22
【问题描述】:
我想创建一个 php 脚本来执行一个 shell 命令并返回它的输出。服务器需要私钥。当我第一次决定测试它时,我创建了这个:
<?php
$command = "ls";
$output = shell_exec($command);
echo "<pre>$output</pre>";
?>
效果很好。但是当我将$command 更改为我真正想要运行的命令时:
$command = "/etc/init.d/mycontrollerd status /etc/mycontrollerconfig";
它给了我这个输出:
You need root privileges to run this script
我猜我需要使用sudo。当然,这需要将 pem 文件放在服务器上的某个位置。假设我这样做,$command 究竟应该是什么?我应该使用shell_exec()、exec()、system() 还是别的什么?
【问题讨论】:
标签: php shell-exec