Page MenuHomePhorge

Get the HOME of the user running the PHP webserver
Closed, ResolvedPublic

Description

It's really unclear to me the universal way to get the home of the user running the webserver (www-data) OR PHP FPM in both Linux / Windows etc.

This is really needed since the Config page for example executes git command from the webserver user to find the current version, but, git needs to know the HOME of the user. So we probably may need to just pass an $HOME environment variable with specifically created content. Since, spoiler, it seems nobody will do that for us, not even variables_order = "EGPCS".

Questions

  1. Do we have a "get user HOME" function in Phorge or Arcanist?
    • It seems Yes. For example in Phorge's PhabricatorDaemonManagementWorkflow.php it uses $current_user = posix_getpwuid(posix_geteuid());
  2. What is the proposed equivalent for Windows?

As far as I can see, this approach works in Linux for mod_php:

# Linux/Unix
$home = posix_getpwuid(posix_geteuid())['dir']; // if you are www-data you get /var/www

# Windows
$home = getenv('USERPROFILE');
  • We have code for Linux mod_php: it works
  • We have tested in Linux PHP_fpm: it works
  • We have tested in Linux CLI: it works
  • We have code for Windows: USERPROFILE works - https://t.me/phpita/80694

Notes:

  • $_SERVER is probably always usefulness for this problem (in Linux php_fpm does not have anything that can be assumed as a correct Unix user home)
  • $_ENV in default Linux php_fpm (most common environment?) has just the PATH and not any HOME
  • avoid getmyuid() since it's about the Unix user owner of the current current file, and it has anything to do with the current user
  • probably posix_geteuid() (effective UID) is more meaningful in PHP FPM than posix_getuid() (real UID) but it's just a guess - https://stackoverflow.com/q/32455684/3451846