Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get apache linux user from php

Tags:

php

apache

I'm on a foreign linux system and need to determine the user that apache runs on (and so does php).

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.

like image 201
Mario Mueller Avatar asked Apr 30 '09 08:04

Mario Mueller


People also ask

How do I find apache username?

lsof command 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 is the user for PHP?

1 Answer. The user that runs apache/php is www-data .

What user server is running under Linux?

Apache is the most common web server used on Linux systems. It is a free and open-source web server that delivers web content through the Internet. One of the most common web application stacks involves Linux, Apache, MySQL, and PHP.

Under what user account does apache Web server service operate?

By default, all Apache services are registered to run as the system user (the LocalSystem account).


2 Answers

You can call the php exec function to execute whoami:

<?php echo exec('whoami'); ?> 
like image 164
grantc Avatar answered Sep 22 '22 03:09

grantc


see posix_getuid() and posix_getpwuid()

like image 20
Anonymous Avatar answered Sep 26 '22 03:09

Anonymous