简体   繁体   English

我可以从php_info()中找出哪个用户正在运行php吗?

[英]Can I find out which user php is running under from php_info()

I have to support someone in setting up a PHP website on an IIS 7 server to which I don't have any remote access to. 我必须支持某人在我没有任何远程访问权限的IIS 7服务器上建立PHP网站。 He's having trouble with permissions and doesn't know which user PHP is running under to give it correct write permissions on the document root. 他在权限上遇到麻烦,并且不知道运行哪个用户PHP来为它提供对文档根目录的正确写权限。 I've asked him to make a file with <?php php_info(); ?> 我已经请他使用<?php php_info(); ?>创建文件<?php php_info(); ?> <?php php_info(); ?> in it, and he has, I have access to it but I don't know where to look for the php user. <?php php_info(); ?> ,他有,我可以访问它,但我不知道在哪里寻找php用户。

What would be the correct place to look for the user that PHP is running under? 寻找在其下运行PHP的用户的正确位置是什么?

You can run below in file.php 您可以在file.php中运行以下内容

<?php
echo exec('whoami');
?>

This will give you user name. 这将为您提供用户名。

OR 要么

$user = getenv('APACHE_RUN_USER');

OR 要么

lsof -i
lsof -i | less
lsof -i | grep :http

Run any of will give user is running which service. 运行任何一个都会给用户正在运行哪个服务。

Check this tutorial for more information about IIS and application pool identities. 查看本教程 ,以获取有关IIS和应用程序池标识的更多信息。 The key factor is the user the webserver is running under. 关键因素是运行Web服务器的用户。 On *nix system this is usually www-data, for IIS servers you can work with the "DefaultApplPool" group. 在* nix系统上,这通常是www-data,对于IIS服务器,您可以使用“ DefaultApplPool”组。 So give this group the required permissions through permissions tab of the folders properties. 因此,通过文件夹属性的“权限”选项卡为该组提供所需的权限。

There is one built in function in PHP get_current_user() which allows you to see owner of php script. PHP get_current_user()中有一个内置函数,可让您查看php脚本的所有者。

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM