How to Show PHP Configuration Information on Localhost

Sheeraz Gul Feb 02, 2024
  1. Set Configuration to Run the phpinfo() on Localhost
  2. Use phpinfo() to Show the Configuration Information of PHP
How to Show PHP Configuration Information on Localhost

The phpinfo() is a built-in function in PHP that outputs all the information of PHP configuration on the localhost. We must create a PHP file with just a simple phpinfo() function call.

Sometimes, the file may not work and outputs a 404 error. This tutorial demonstrates how to set and run phpinfo() in PHP.

Set Configuration to Run the phpinfo() on Localhost

Running phpinfo() on localhost is a simple task. Your local host should know how to run a PHP file for this task.

Open the httpd.conf file from your localhost library and check if PHP is correctly configured. The configuration should be like this:

PHPIniDir "C:/php74"
AddHandler application/x-httpd-php .php
LoadModule php7_module "C:/PHP74/php7apache2_4.dll"

Once the configuration is set, restart your localhost, and then you can run phpinfo().

The configuration above is for apache localhost.

Use phpinfo() to Show the Configuration Information of PHP

First, you have to create a file info.php with the code below and run it on your localhost:

<?php
phpinfo();
?>

The simple phpinfo() will return all the information of installed PHP.

Output:

PHP Info Output

phpinfo() also takes constant parameters to show the detailed information. For example, INFO_CREDITS will show the credits information of PHP.

Example:

<?php
phpinfo(INFO_CREDITS);
?>

Output (will show credits only):

PHP Credits Info

The other constants used for the detailed information through phpinfo() are below.

Constant Usage
INFO_GENERAL Shows the general PHP information.
INFO_CONFIGURATION Shows the php.ini information.
INFO_ENVIRONMENT Shows the information of environment variables.
INFO_MODULES Shows the information of loaded modules.
INFO_VARIABLES Shows the information of all predefined variables.
INFO_LICENSE Shows the license information of PHP.
INFO_ALL Show all the information described above.

Put the constant as a parameter in phpinfo() and run it to show the information.

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook