If you need to determine the account under which PHP is running on a web server, you can use the code below:
<?php
passthru("whoami");
?>
On a web server running Apache as the
web server software, you can expect this to be the same as the account
under which Apache is running, so you may see apache
as the
result. Or, if the system is using virtual hosts and suexec
, e.g.,
with an SuexecUserGroup
directive in Apache's
httpd.conf
file for the virtual host, then you may see the userid
associated with the website listed.
If you wish to see the user ID, group ID, and groups for the account under which PHP is running, you can use the following code:
<?php
system("id -a");
?>
If PHP and Apache are running under the apache userid, you might see output similar to the following:
uid=48(apache) gid=48(apache) groups=48(apache)
Reference: