this is not always the case, since calling php from inside console, invokes the cli-sapi (php-cli) which may-, but often NOT is the php-sapi used by the server.
In case your server uses the fpm sapi (php-fpm) you should call the phpinfo on console different. Since the php-fpm is called different on different linuxes and is not handled by the update-alternatives mechanism on debianoids, you should search the binary with
find $(echo $PATH | tr : " ") -name *fpm* -type f 2>/dev/null
you then should see one or more versions of the php-fpm binary with version string. Caling that binary with the -i
flag gives you the phpinfo which equals to <?php phpinfo() ?>
.
In case you have installed multiple versions and you know the version you are using is e.g. 8.1, then you can call it directly with
$(find $(echo $PATH | tr : " ") -name *fpm* -type f 2>/dev/null | grep 8.1) -i
or if you want to script it:
phpversion=8.1
fpm_binaries="$(find $(echo $PATH | tr : " ") -name *fpm* -type f 2>/dev/null)"
$(echo $fpm_binaries | grep $phpversion) -i
You can create a bash alias:
alias php-fpm='$(find $(echo $PATH | tr : " ") -name *fpm* -type f 2>/dev/null | grep 8.1)'
which makes the call of php-fpm execute the fpm-sapi for the version 8.1.
Now you can pipe- and grep for any information you are looking for without having to expose your sensitive phpinfo on the web:
php-fpm -i | grep "$searchstring"
(Of course this can also be made easier by calling the binaries directly, but I wanted to present a solution that works on practically all Linux versions with multiple php-versions installed.)