How to Use phpinfo() to View PHP Server Details
This article explains how to use the built-in phpinfo()
function in PHP to display comprehensive server, environment, and
configuration details. You will learn how to create a simple PHP script
to output this information, customize the output to show specific
configuration areas, and implement essential security measures to
protect your server data.
To display your server’s PHP configuration details, you need to
create a single PHP file on your web server and call the
phpinfo() function.
Step 1: Create the PHP File
Using a text editor or a code editor, create a new file named
info.php (or any name ending with .php) and
add the following code:
<?php
phpinfo();
?>Step 2: Upload and Run the Script
Upload this file to the root directory of your web server (commonly
public_html, www, or htdocs)
using FTP, SFTP, or your hosting control panel’s file manager.
Once uploaded, open your web browser and navigate to the file’s URL,
for example: http://yourdomain.com/info.php or
http://localhost/info.php for local environments.
The browser will display a detailed, formatted page containing information about your PHP version, active extensions, server environment, OS version, paths, and local/master values for php.ini directives.
Step 3: Customizing the Output (Optional)
By default, phpinfo() displays all available
information. However, you can pass specific constants to the function to
restrict the output to certain details:
INFO_GENERAL: Shows the OS, Web Server, System, and PHP build date.INFO_CREDITS: Displays PHP credits and developers.INFO_CONFIGURATION: Displays local and master values for PHP directives.INFO_MODULES: Lists all compiled modules and their respective settings.INFO_ENVIRONMENT: Shows all Environment variables.INFO_VARIABLES: Displays all EGPCS (Environment, GET, POST, Cookie, Server) variables.
For example, to display only the configuration and loaded modules, use the following code:
<?php
phpinfo(INFO_CONFIGURATION | INFO_MODULES);
?>Important Security Warning
The output of phpinfo() contains highly sensitive server
information, including absolute file paths, server software versions,
and environment variables that may contain database credentials or API
keys. If malicious actors gain access to this page, they can use the
details to identify vulnerabilities in your system.
Always delete the info.php file immediately after you
have gathered the required information. Do not leave this file publicly
accessible on a live production server.