What is phpinfo() Function and How to Create phpinfo File and Check PHP Information?

The phpinfo() is a very important function which gives us information about the PHP configuration and installation in our system. Every system is different and hence this information would be different for each of them as well. It can also be used to identify installation and configuration problems.

Use of phpinfo()

PHPINFO() gives details like platform information, server environment information, PHP details like version, license info, HTTP headers, and the PHP license. It also includes PHP compilation options, extensions, OS version information, etc. Whenever the function is called without any argument then it will all the information about the PHP configuration in the system, some of the information includes:

  • PHP compilation options and extensions information
  • PHP version
  • Server information (if compiled as a module)
  • PHP environment
  • HTTP headers
  • HTTP headers
  • HTTP headers
Note: It is also used as a debugging tool as it contains data like Environment, GET, POST, Cookie, Server data also called EGPCS.

Let’s see an example to run the function, just create a file as phpinfo.php and add the code written below in it:

Example:
<?php phpinfo(); ?>

Now save the file and run it using the PHP server installed in your system. You will get the information displayed like in the image given below:

PHP tutorial

Other than all the information what if you want specific information like info about variables only or license only. You can do that you just have to pass an argument in the function either as name or their specific value. Every information has given a particular keyword and a value associated with it which we can use in the PHPINFO() function to get only selective information. Look at the table given below:

Name (constant) Value Description
INFO_GENERAL 1 Information about platform, php.ini location, web system, etc.
INFO_CREDITS 2 Return all the information about the authors, documentation and other credits.
INFO_CONFIGURATION 4 It returns PHP core configuration information.
INFO_MODULES 8 Shows information about all the Loaded modules and their settings.
INFO_ENVIRONMENT 16 Returns all Environment Variable information.
INFO_VARIABLES 32 Shows all predefined variables like GET, POST, etc.
INFO_LICENSE 64 Information about PHP license
INFO_ALL -1 Shows all the information.
Note: php_info(INFO_MODULES) and php_info(8) and also all other constants and their respective values give the same result, i.e. they can be used interchangeably.
Note: php_info() and php_info(INFO_ALL) gives the same output.

CREATE A PHPINFO.PHP PAGE Live in your hosting or server

If you have a website live on a server then you can create a phpinfo file in that server to get the information about PHP configuration on that server. It helps in debugging an error sometimes as it contains useful information that one can use in case of any error in the PHP system of the server.

Let’s see the steps to create a phpinfo file on the server:

Step 1: Open your website files using a File Manager or FTP.

Step 2: Open your website’s root directory:

  • Plesk: httpdocs
  • cPanel: public_html

Step 3: Create a new file named phpinfo.php in the root directory. You can create this file anywhere in the subdirectories also but it is easier to locate in the root directory.

Step 4: Add this content into your phpinfo.php file:

Example:
<?php phpinfo(); ?>

Step 5: Save the File.

The file is created. Now you can get all the information about the PHP configuration of your hosting server. Just go to this URL: http://www.example.com/phpinfo.php

Note: If the file is in any subdirectory then you have to add that full path as URL.

Now all the information about PHP will be displayed on your screen. If you want to look at a particular piece of information, then you can search for it by using the constant name as written in the table above. To start searching try these shortcuts:

  • Windows: CTLR + F
  • Mac: CMD + F

A search box will open, now try searching for information like ‘memory’, you will be navigated to the information if found.

PHP tutorial
Note: If you don’t want to show your phpinfo() page all the time, then you can disable it by renaming the file.

Conclusion:

Now you’ve learned how to create a phpinfo.php file and how to check PHP information via in localhost or your hosting control panel. Try to use it in your system or your live server and see the result. Thank You.



Color Picker

List of color names supported by all browser »



Character Code

List of character codes to display special character »



Language Code

List of all language supported by all browser »



Country Code

List of Country code supported by all browser »

Latest Updates

PHP Introduction

How to Run a PHP program in Xampp?

How can I create a phpinfo.php page?

How to Define a Variable in PHP

PHP Echo and Print Statements

Working with PHP Operators

Understanding the PHP Data Types

How to Write Comments in PHP

How to Define a Constant in PHP

PHP if...else...elseif Statements