How to get phpinfo to display info

Hi

I’m using Nextcloud version 22.2.3. I tried creating a phpinfo.php file which I placed in the root folder of the Nextcloud installation. When I try to access it from my browser - it does not show the information from the phpinfo file - instead I’m just seeing the normal Nextcloud.

I would like the information from the phpinfo file. Any idea how I should set it up?

The PHP version can be checked in the Settings/System overview. Do you need more?

I would like to see the settings/modules/extensions. It would be nice if it was possible to see within Nextcloud - or an explanation how I could let it be shown temporarily without Nextcloud “hijacking” the URL.

Nobody having any idea how to do it?

Where you created the file (ex info.php) you can just do php info.php on the console
info.php should consist of

INFO.PHP
<?php phpinfo() ?>

this equals the output of

php -i

I would like to have it in the root folder of the my Nextcloud installation - so I get the information that applies to the website (I’m not that used to Linux/Apache). I will of course remove it when I do not use it.

The problem is that when i enter www.mysite.com/phpinfo.php I’m redirected to www.mysite.com/apps/files/ - I guess that there might be some mod_rewrite rules? Any idea how I bypass them for just this file?

I do get the info when I add the file in the main installation directory.
Obviously it’s a setting for you.

You can still get the values from command line

php -c /etc/php/8.1/apache2/php.ini -c /var/www/nextcloud/.user.ini -i

Notice the PHP Version 8.1 8.0 or 7.x and the /var/www/nextcloud as installation directory.

I found the solution. In the .htaccess file in the root of the site i change i added the filename in the below part (I have marked it with ** in front of phpinfo and ** after

#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 /
ErrorDocument 404 /
<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]
  RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]
  RewriteCond %{REQUEST_FILENAME} !\.(css|js|svg|gif|png|html|ttf|woff2?|ico|jpg|jpeg|map|webm|mp4|mp3|ogg|wav|wasm|tflite)$
  RewriteCond %{REQUEST_FILENAME} !/core/ajax/update\.php
  RewriteCond %{REQUEST_FILENAME} !/core/img/(favicon\.ico|manifest\.json)$
  RewriteCond %{REQUEST_FILENAME} !/(cron|public|remote|status|**phpinfo**)\.php
  RewriteCond %{REQUEST_FILENAME} !/ocs/v(1|2)\.php
  RewriteCond %{REQUEST_FILENAME} !/robots\.txt
  RewriteCond %{REQUEST_FILENAME} !/(ocm-provider|ocs-provider|updater)/
  RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
  RewriteCond %{REQUEST_FILENAME} !/richdocumentscode(_arm64)?/proxy.php$
  RewriteRule . index.php [PT,E=PATH_INFO:$1]
  RewriteBase /
  <IfModule mod_env.c>
    SetEnv front_controller_active true
    <IfModule mod_dir.c>
      DirectorySlash off
    </IfModule>
  </IfModule>
</IfModule>
2 Likes

Just want to thank you for this simple but nice trick, I come again and again to this post to “enable” a debug mode on each OS upgrade (to check if NC is tricking me with php versions)

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.)

1 Like

I created a PR to get this change added into NC officially. I hope you don’t mind! You’re credited in the submission. :slight_smile:

Between running into this myself a few times and this thread having several thousand views, seemed to make sense.

A user/admin still has to provide their own phpinfo.php whenever it’s wanted (and remove it after!), but having it flow through the default NC .htaccess means standard PHP troubleshooting steps can be followed without the unexpected additional layer to sort out.

Since nextcloud 28, phpinfo is provided by the Nextcloud server itself. It only needs to be activated with occ:

./occ config:app:set --value=yes serverinfo phpinfo

as described → here ←


ernolf

1 Like

Nice. Didn’t know they added that. Thanks for the info. :slight_smile: