I wrote a parser in 2019 that prepares and outputs phpinfo()
for my OpenSource Hosting-Panel "fruithost".
Here I had found a way to output the phpinfo()
with the scope of a previously specified directory, since a hosting user can also create a php.ini
in subdirectories.
The special thing about the method was that the whole thing is executed directly via the web server and PHP-FPM
and thus exclusively uses the phpinfo();
of a previously specified directory.
Unfortunately for me, I had lost the part at that time due to git stashing, my efforts to recover the file (here I have already exhausted all conceivable possibilities) were in vain.
Now I want to start the whole topic anew and look again for the possibility to implement my intention.
Problem with the story:
I can't just print phpinfo()
, because here the configuration is printed, which runs over a completely different context. As you know, there is no phpinfo('/path/to/php.ini')
method. 🙄
Using the PHP CLI via php -i -c /destination/path/
does not work here, because the whole thing is executed by php-cli with a different context and also the output does not happen in HTML. In particular, other PHP modules that do not represent the configuration of PHP-FPM are loaded here.
Desired behavior:
On the screenshot you can see what is needed:
At the very top right, a domain can be selected. For example example.com
or sample.net
. The domains are located in the following path:
/var/fruithost/
<username>
/<domain>
/
If the user selects a domain in the upper right corner (example sample.net
), phpinfo()
uses the directory /var/fruithost/<username>/sample.net/
, because a php.ini
could be located here.
This base is then used to control the output of phpinfo()
.
What are the ideas and approaches?
For those interested: I had uploaded a screenshot back when I finished the 2019 part, this is what the result looked like:
I have found a other solution, with better way to call PHP-FPM
directly:
<?php
# Executement-Path
$path = '/var/fruithost/users/admin/' . $this->domain . '/';
# PHP-fpm
$socket = '/run/php/php8.2-fpm.sock';
# Create temporarely phpinfo();
$tmp = '.~fh.tmp.info.php';
file_put_contents(sprintf('%s%s', $path, $tmp), '<?php phpinfo(); ?>');
$args = '';
foreach([
'SCRIPTS_DIR' => $tmp,
'HOME' => $path,
'PWD' => $path,
'DOCUMENT_ROOT' => $path,
'SCRIPT_FILENAME' => sprintf('%s%s', $path, $tmp),
'REQUEST_METHOD' => 'GET'
] AS $name => $value) {
$args .= sprintf('%s=%s \\%s', $name, $value, PHP_EOL);
}
$command = sprintf('%scgi-fcgi -bind -connect "%s" 2>&1', $args, $socket);
$result = shell_exec($command);
@unlink(sprintf('%s%s', $path, $tmp));
print_r($result);
?>
I think my previous version from 2019 has no used temporare files, but its another (ugly) way here.