I'm on a foreign linux system and need to determine the user that apache runs on (and so does php). Show The aim: I need to get the owner of the script (this is no problem as I can use SplFileInfo) and compare it to the owner of the apache process. I'm open to any alternative proposals. Regards, Mario Edit: Additional info: The script is a thumbnail generator, that uses an XML file to generate thumbs from larger images. The script needs to create folders and write files. As I cannot influence the php configuration and I do not have any shell access, this has to be done very silently. The creation process stopps via exception and sends a mail on failue. As most of php's function cannot throw exceptions on failue, I need some manual checks to determine the environment I'm in. Therefore I need the apache user to compare it to some directory or fileowner. asked Apr 30, 2009 at 8:22
Mario MuellerMario Mueller 1,4102 gold badges13 silver badges16 bronze badges 2 You can call the php exec function to execute whoami:
answered Apr 30, 2009 at 8:39
grantcgrantc 1,70312 silver badges13 bronze badges 5 see posix_getuid() and posix_getpwuid() answered Apr 30, 2009 at 8:41
AnonymousAnonymous 2,9114 gold badges23 silver badges23 bronze badges Some complicated answers here. This works for me:
Not sure if this is just a new thing that been added to apache since this question was asked but it's definitely there now. answered Jul 1, 2013 at 23:10
Jamie CarlJamie Carl 1,19613 silver badges21 bronze badges 1 phpinfo will dump a lot of system information. For apache2 installs, there is a section that displays the apache user and group ids. Try creating a php script that just has one line, a call to phpinfo(), and open it in your web browser. answered Apr 30, 2009 at 8:30
zombatzombat 91k24 gold badges155 silver badges164 bronze badges 2 Some php script must be run on apache user (cli), whoami is not appropriate in that case. Here is my solution :
answered Nov 14, 2018 at 8:37
atmacolaatmacola 3252 silver badges8 bronze badges (PHP 4, PHP 5, PHP 7, PHP 8) get_current_user — Gets the name of the owner of the current PHP script Descriptionget_current_user(): string Returns the name of the owner of the current PHP script. ParametersThis function has no parameters. Return ValuesReturns the username as a string. ExamplesExample #1 get_current_user() example
The above example will output something similar to: Current script owner: SYSTEM See Also
justin samuel ¶ 16 years ago
south dot bucks at gmail dot com ¶ 10 years ago
s dot bond1 at lse dot ac dot uk ¶ 15 years ago
chris at ocproducts dot com ¶ 2 years ago
nick at little-apps dot org ¶ 9 years ago
login dot naitsirch at arcor dot de ¶ 7 years ago
How do I find apache username?Linux: Find Out Apache User Name. apache2 (1st column) – Apache service / server name.. 4122 (2nd column) – Apache server PID.. www-data (3rd column) – Apache server username for PID. This gives you apache username.. What user is PHP?1 Answer. The user that runs apache/php is www-data .
How do I find the web server group?To find the web server user's group:. CentOS: grep -E -i '^user|^group' /etc/httpd/conf/httpd.conf. Copy. or. grep -Ei '^user|^group' /etc/httpd/conf/httpd.conf. Copy. ... . Ubuntu: ps aux | grep apache to find the apache user, then groups <apache user> to find the group. Typically, the username and the group name are both www-data.. |