【发布时间】:2018-12-02 00:42:52
【问题描述】:
我正在编写将 disqus cmets 转换为 HashOver 系统的代码,我有这样的代码:
// $threads is list of threads from disqus api that I cached on disk
foreach ($threads as $thread) {
$dir_name = getSafeThreadName(preg_replace("%^https?://[^/]+%", "", $thread['link']));
$dir = 'threads/' . $dir_name;
if (!is_dir($dir)) {
mkdir($dir);
chmod($dir, 0774);
}
// ...
// $thread_posts are $post that belong to $thread
foreach($thread_posts as $post) {
$xml = new SimpleXMLElement('<comment/>');
// ...
// $name_arr is array of numbers for HashOver comments
$fname = $dir . '/' . implode('-', $name_arr) . ".xml";
$f = fopen($fname, 'w');
fwrite($f, $xml->asXML());
fclose($f);
chmod($fname, 0664);
}
}
它为我在线程中的每个帖子创建了目录,该目录由所有者apache:apache 读写,内部有像1.xml 这样的文件,所有者为root:root
为什么是root:root?我怎样才能做到apache:apache?
编辑:
这不是重复的,我不想将权限从root:root 更改为apache:apache,这可以使用chown 完成,但我想这样做所以它不会将其更改为@ 987654331@排在第一位,我也想知道为什么改成root:root。对我来说,这看起来像是 php 或 apache 中的错误,或者我这边 apache 中的一些错误配置。我不认为是代码,因为它只是打开、写入和关闭文件。
【问题讨论】:
-
你是在浏览器中运行它还是使用 CLI
-
@RiggsFolly 来自浏览器。
-
@DaFois 这不是重复的,因为它没有更改权限,而是使其不会更改为
root:root,但像其他文件一样保留apache:apache,并且在查看其他问题时似乎对于 chown,您将需要修改 sudoerrs,这对我来说不是一个选项。 -
看起来您的服务器配置错误,而 Apache 进程实际上是以 root 身份运行的。
标签: php file-permissions