我将如何创建一个php脚本来执行shell命令以将文本写入另一个php文件? 并且没有任何 sudo 问题。到目前为止,我有这个。
<?php
include("inc/config.php");
$command = "sed -i '$ a'this is line 2 without redirection' admin.php";
$command1 = "cat admin.php";
$output = shell_exec($command);
$output1 = shell_exec($command1);
echo "<pre>$output</pre>";
echo "<pre>$output1</pre>";
?>
我使用了chown wwwdata和chmod 777
您的脚本需要在有权执行您需要执行的所有操作的帐户下运行。 就是这么简单。