Find out what user and group Apache is running as

This is useful for when you are trying to migrate a WordPress or HTML website and can't figure out why FTP won't allow you to go into folder or save files you have edited.

To find the user and group your PHP process (web server) run under you could try to run the following PHP script:
Just create a file apache.php in the root and browse to it once you have included this code:

    // use posix to get current uid and gid
    $uid   = posix_geteuid();
    $usr   = posix_getpwuid($uid);
    $user  = $usr['name'];
    $gid   = posix_getegid();
    $grp   = posix_getgrgid($gid);
    $group = $grp['name'];
    // try to create a file and read it's ids
    $tmp = tempnam ('/tmp', 'check');
    $uid = fileowner($tmp);
    $gid = filegroup($tmp);
    // try to run ls on it
    $out = `ls -l $tmp`;
    $lst = explode(' ',$out);
    $user  = $lst[2];
    $group = $lst[3];
echo "Your PHP process seems to run with the UID $uid ($user) and the GID $gid ($group)\n"; ?>

Alternatively, you can use short script with phpinfo(), see section User/Group in output:

  • web_development/devops/apache-user.txt
  • Last modified: 2020/09/18 02:50
  • by jimboobrien