Just run the PHP script below.
Don't forget to change the input data for your setup:
$apacheEnvVarsConfFile - the apache conf file that defines the user to be used; in this example it was /etc/apache2/envvars and the line defining it was export APACHE_RUN_USER=www-data
$dirThatYouWantToTest - the directory for which you want to read the user/group permissions
<?php
## define input data
$apacheEnvVarsConfFile = '/etc/apache2/envvars';
$dirThatYouWantToTest = '/var/www';
## compute the information that is needed
$data = array();
$data['apacheUser'] = str_replace('export APACHE_RUN_USER=', '', exec('cat '.$apacheEnvVarsConfFile.' | grep APACHE_RUN_USER'));
$dirStat = stat($dirThatYouWantToTest);
$data['dirTested'] = $dirThatYouWantToTest;
$data['dirUser'] = posix_getpwuid($dirStat[4])['name'];
$data['dirGroup'] = posix_getgrgid($dirStat[5])['name'];
$data['dirPerms'] = substr(sprintf('%o', fileperms($dirThatYouWantToTest)), -4);
echo '<pre>';print_r( $data );echo '</pre>';
## the code above will produce the following output (example):
/*
Array
(
[apacheUser] => www-data
[dirTested] => /var/www
[dirUser] => john
[dirGroup] => john
[dirPerms] => 0755
)
*/