This guide will show you how to create a phpinfo file and use it to check the PHP configuration information on your web server.
phpinfo() is a PHP function that outputs information about PHP’s configuration when invoked.
The function outputs a large amount of information about the current state of PHP on the system. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.
The function takes zero or 1 parameter. This parameter happens to be a flag that you can use to specify what you want to print out. It returns true on success, false on failure.
phpinfo ( int $flags = INFO_ALL ) : bool
- INFO_ALL: (-1) -> Shows all of the above. This is the default Flag
- INFO_GENERAL: (1) -> The configuration line, php.ini location, build date, Web Server, System, and more.
- INFO_CREDITS: (2) -> PHP Credits.
- INFO_CONFIGURATION: (4) -> Current Local and Master values for PHP directives.
- INFO_MODULES: (8) -> Loaded modules and their respective settings.
- INFO_ENVIRONMENT: (16) -> Environment Variable information.
- INFO_VARIABLES: (32) -> Shows all predefined variables from EGPCS (Environment, GET, POST, Cookie, Server).
- INFO_LICENSE: (64) -> PHP License information.
Let’s Create the phpinfo File Now
Using your favorite text editor create a blank PHP and name it phpinfo.php. Take note that the file can be named anything you want, just make sure it is a good descriptive name.
Add the following line into the phpinfo.php file.
If you want to change the default results printed out you can use one of the seven other parameters (other than the default parameter). For example:
Upload the phpinfo.php file to your server’s document root folder using an FTP client such as FileZilla or your web host’s File Manager if you are using a hosting control panel such as CPanel. If you are on a localhost development environment then simply save it to the document root folder.
Check PHP Information Using a Browser
Now that the file has been uploaded onto the web server’s document root we can invoke it by running http://yourdomain.com//phpinfo.php.
You should see output similar to this:
Note: phpinfo() outputs plain text instead of HTML when using the CLI mode.
That’s it! You now have access to the PHP configuration for your environment whenever you need it.
As you create a phpinfo file you must be cautious about security. Do not leave this file as is when you do not need it. You can temporary disable it by renaming it to something like phpinfo.php_disabled and rename it back to the original as needed.