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

3.1k Views Asked by At

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. 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. I've asked him to make a file with <?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.

What would be the correct place to look for the user that PHP is running under?

3

There are 3 best solutions below

0
On

There is one built in function in PHP get_current_user() which allows you to see owner of php script.

Reference

4
On

You can run below in 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.

0
On

Check this tutorial for more information about IIS and application pool identities. The key factor is the user the webserver is running under. On *nix system this is usually www-data, for IIS servers you can work with the "DefaultApplPool" group. So give this group the required permissions through permissions tab of the folders properties.