How to View Detailed Information About PHP With phpinfo() Function

In php on 2~4 minutes
How to View Detailed Information About PHP With phpinfo() Function

When we develop PHP web applications and sites, often we need to get information like available modules, environment variables, server information. In order to get these pieces of information, we can simply use the phpinfo() built-in PHP function.

View All PHP Information

First, create a PHP file and add the following code.


Place that file in your web server document root directory (Ex: www) and access it from your web browser. It will display all the information about your PHP installation.

View Specific Information About PHP

By default, phpinfo() PHP function displays all the information. But we can narrow it down to specific categories like general information, configurations, modules, environment variables and etc. For that, we need to pass an additional parameter to the phpinfo() function.

  • INFO_GENERAL - system information, build date, php.ini configuration file path.
  • INFO_CONFIGURATION - information about PHP directives such as display_errors, file_uploads, log_errors, post_max_size, upload_max_filesize, upload_tmp_dir and etc.
  • INFO_MODULES - information about loaded modules such as bcmath, curl, gd, hash, json, mbstring, mysqli, openssl, PDO, pgsql, session, sockets, sqlite3, xdebug, OPcache, zip and etc.
  • INFO_VARIABLES - information about the server such as DOCUMENT_ROOT, REQUEST_URI, REQUEST_METHOD, HTTP_USER_AGENT and cookie information. These are available in $_SERVER and $_COOKIE variables.

The complete list is available at PHP Documentation.

CLI Version Of phpinfo()

Instead of editing files and accessing them using a web browser, you can even obtain the above-mentioned information by using the CLI. For that, open a terminal window and run the following command. It will display about PHP in the terminal.

php -i

If you need, you can even narrow down and filter the output by using the grep command with -i (ignore case) flag like below. So it will only display information related to xdebug.

php -i | grep -i 'xdebug'
You May Also Like: