0

我在我的 Mac 上安装了 XAMP,我尝试运行命令 - ps axo user,group,comm | grep httpd以了解 apache 正在运行的用户身份。我得到了多个结果,一个是root,另一个是nobody。那么 apache 是作为什么运行的呢?一个root或nobody,为什么我得到root和nobody?是不是因为 httpd 以 root 身份开始,然后变成了没人?

ps axo user,group,comm | grep httpd我得到的结果是 -

根 20 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd
没人 -1 /Applications/XAMPP/xamppfiles/bin/httpd

其次,当我执行以下脚本时 - echo shell_exec('whoami');(来自https://stackoverflow.com/questions/2509334/finding-out-what-user-apache-is-running-as)我得到的结果是 -nobody

我想知道用户的原因是因为 php 引擎实际上能够执行 web 服务器根目录之外的 php 文件(mysql_details.php)。而这个 mysql_details.php 具有以下权限 -rwxr--r--即仅读取其他和组的权限。所以如果apache用户是nobody,那么它如何执行mysql_details.php。

谢谢,普拉特。

4

1 回答 1

1

主 Apache 进程以 root 身份运行 - 其他进程以无人身份运行。处理请求的唯一进程是那些以无人身份运行的进程,因此如果有人试图访问无人无法访问的文件,他们将收到错误消息(而 root 将能够访问该文件)。

如果你需要执行文件,你可以做一些事情:

  1. Have nobody own the file. This will give nobody full read/write/execute access to the file, while preventing other users from writing or executing the file.
  2. Add nobody to a group, and give that group execute access on the file. Anyone who is in the group would be able to execute the file, but only the owner would be able to write to it (which would not be nobody).
  3. Allow anyone to execute the file. This is probably not a good idea, as any user would be able to execute the contents at varying permission levels. It'd probably be best to use one of the above two.
于 2012-06-30T20:56:35.783 回答