Using phpinfo() – Display PHP Configuration & Modules
phpinfo() is a built-in PHP function that shows a full page of information about your PHP: the version, the configuration file in use, the settings and the loaded modules (extensions).
When PHP is installed, many extensions come with it. Some are enabled and some are not. Extensions add features to PHP. For example, the date extension gives date and time functions, mysqli is used to connect with MySQL, and curl is used for APIs. It is good to look at them.
Example using phpinfo()
<?php
phpinfo();
?>
Save it as info.php in your project folder, and open it with http://localhost/info.php. You will see a long page with many tables.
What you can find on that page
- The PHP version and the system where it runs.
- The path of the loaded
php.inifile, so you know which file to edit. - Settings like
upload_max_filesizeandmax_execution_time. - The list of all loaded extensions, like mysqli, curl and mbstring.
Note:
Security: The phpinfo page shows private details about your server. Never leave such a file on a live website. Delete it after you check what you need.
Other ways to check
<?php
echo "PHP version: " . PHP_VERSION . "<br>";
var_dump(extension_loaded("mysqli"));
echo ini_get("upload_max_filesize");
?>
Output:
Sample output, yours can be different
PHP version: 8.2.12
bool(true)
2M
PHP_VERSIONgives the version.extension_loaded("name")tells if an extension is on.ini_get()reads one setting.- In the command line,
php -v,php -m(modules) andphp -i(same as phpinfo) work.
Related: PHP Installation.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Introduction |
| PHP Terminology |
| PHP Installation |
| PHP Syntax |
| PHP Comments |
| PHP exit() Function |
| Exercises & Assignments |
|---|
| Write a program to print “Hello World” using echo |
| Simple Tips for PHP Beginners |
| Experiment with Basic PHP Syntax Errors |
| Using phpinfo() – Display PHP Configuration & Modules |