Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check what user php is running as?

Tags:

php

apache

People also ask

What user is php running as?

The user that runs apache/php is www-data . Run sudo chown -R www-data:www-data /var/www/deploy. log to make the file editable by the web server. The other files you want to perform operations on also need to be writable by the webserver.

What user is PHP-FPM running as?

By default the web server and php-fpm runs with the user called www-data.

How can I see what processes are running php?

Depending on your setup this could be managed via fast-cgi or mod_php or even php-fpm. If you use mod_php , then there will be no "php processes" visible for ps . You can still see if your PHP engine is in use by using lsof : $ lsof -ln [...]

What is Whoami php?

The PHP manual says that exec('whoami') returns "the username that owns the running php/httpd process" Link.


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


If available you can probe the current user account with posix_geteuid and then get the user name with posix_getpwuid.

$username = posix_getpwuid(posix_geteuid())['name'];

If you are running in safe mode however (which is often the case when exec is disabled), then it's unlikely that your PHP process is running under anything but the default www-data or apache account.


Kind of backward way, but without exec/system:

file_put_contents("testFile", "test");
$user = fileowner("testFile");
unlink("testFile");

If you create a file, the owner will be the PHP user.

This could also likely be run with any of the temporary file functions such as tempnam(), which creates a random file in the temporary directory and returns the name of that file. If there are issues due to something like the permissions, open_basedir or safe mode that prevent writing a file, typically, the temp directory will still be allowed.


More details would be useful, but assuming it's a linux system, and assuming php is running under apache, it will run as what ever user apache runs as.

An easy way to check ( again, assuming some unix like environment ) is to create a php file with:

<?php
    print shell_exec( 'whoami' );
?>

which will give you the user.

For my AWS instance, I am getting apache as output when I run this script.


You can try using backticks like this:

echo `whoami`;

i would use:

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

any of these. You can type em in your ssh command line and you will see what user is listening what service.

you can also go and check this file:

more /etc/apache2/envvars

and look for these lines:

export APACHE_RUN_USER=user-name
export APACHE_RUN_GROUP=group-name

to filter out envvars file data, you can use grep:

 more  /etc/apache2/envvars |grep APACHE_RUN_

exec('whoami') will do this

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