Balis 情報マガジン

phpinfo

📅 October 29, 2026📖 Verified Publication
```html

phpinfo(): The Definitive Guide to PHP Environment Inspection — Pros, Cons, and Security Best Practices

Published: July 2026  |  Read time: 12 min  |  Author: Sapiens AI Editorial Team


Key Takeaways

  • phpinfo() is PHP's most widely used diagnostic function, outputting a detailed snapshot of server configuration, PHP version, extensions, environment variables, and headers in real time.
  • Its primary advantage is immediate visibility into the runtime environment without requiring third-party tools or complex setup.
  • The critical drawback is security exposure — an unsecured phpinfo page leaks sensitive server details that attackers can exploit for targeted vulnerabilities.
  • Best practice is to never leave phpinfo() on production servers; use it only in local or staging environments, and if absolutely necessary, restrict access via authentication and IP whitelisting.
  • Modern alternatives such as php -i, Xdebug, error logging, and monitoring tools like Blackfire or New Relic offer safer, more structured diagnostics.

What Is phpinfo()?

Definition and Purpose

phpinfo() is a built-in PHP function that prints comprehensive information about the current PHP runtime environment. When executed, it generates a full HTML report covering the compiled-in modules, server API, configuration directives, environment variables, PHP license information, and extension details.

First introduced in PHP 3, phpinfo has remained a standard debugging and configuration tool across every major PHP version through PHP 8.3. Its simplicity — a single function call with no arguments — makes it accessible to beginners while still valuable to senior engineers auditing deployment configurations.

What phpinfo() Reveals

Category Details Exposed
PHP Version & Build PHP version number, compiler, OS, build date
Server Information Server software, API type (CGI, FPM, Apache module), hostname, document root
Configuration (php.ini) All active and default directive values including memory limits, upload sizes, timezones
Extensions List of loaded extensions with version numbers and configuration
Environment Variables OS-level variables, web server variables, user environment
Mail & Database SMTP settings, sendmail path, database extension versions (MySQLi, PDO, PostgreSQL)
License & Credits PHP license text, module authors, documentation links

Advantages of phpinfo()

1. Zero Configuration Required

Unlike Xdebug, Blackfire, or New Relic, phpinfo() requires no installation, no extension configuration, and no external dependencies. It is available on any PHP deployment out of the box. This makes it the fastest possible way to verify that PHP is operational on a server.

2. Comprehensive One-Page Overview

A single call to phpinfo() produces a self-contained HTML document that consolidates information typically scattered across multiple configuration files (php.ini, .htaccess, server configs, environment files). For administrators managing multiple servers, this consolidation saves significant time during audits.

3. Rapid Troubleshooting

When a PHP application fails to connect to a database, upload files, or render correctly, phpinfo() immediately confirms whether the relevant extension is loaded, whether the configuration directive is set as expected, and whether the runtime environment matches the deployment target. This eliminates guesswork during incident response.

4. Development Onboarding

New developers joining a project benefit from phpinfo()'s plain-language output, which documents not only what is configured but also what the default value was before modification. This educational aspect helps teams maintain consistent development environments.

5. Version Migration Verification

During PHP upgrades (e.g., PHP 8.1 to 8.3), phpinfo() provides an instant comparison point. By capturing phpinfo output before and after the migration, engineers can verify that extensions remain loaded, deprecated directives have been replaced, and performance-related settings are correctly applied.

Advantage Summary Checklist

Use Case Effectiveness Notes
Quick health check ★★★★★ Instant one-line verification
Extension verification ★★★★★ Shows exact version and status
Configuration audit ★★★★☆ Active and default values shown
Production debugging ★★☆☆☆ Security risk outweighs benefit
Performance profiling ★☆☆☆☆ Requires dedicated tools

Drawbacks and Security Risks

1. Critical Information Disclosure Vulnerability

The most severe risk associated with phpinfo() is information disclosure. An exposed phpinfo page reveals:

  • Server paths — absolute document roots, directory structures, and file locations
  • PHP version — enabling attackers to cross-reference known CVEs for that exact build
  • Installed extensions — identifying vulnerable plugins such as old versions of GD, LDAP, or MySQL extensions
  • Environment variables — including API keys, database credentials, and internal hostnames passed via the server environment
  • Server architecture — operating system, web server type, and compilation details useful for targeted attacks

High-profile incidents have shown that phpinfo pages left accessible on production servers are routinely scanned by automated bots. The National Vulnerability Database (NVD) and tools like Shodan and Censys actively index these endpoints, making them a common entry point for supply-chain and zero-day attacks.

2. No Access Control by Default

phpinfo() provides no built-in authentication, rate limiting, or IP-based restrictions. Once the script is deployed, any visitor — including malicious actors — can access the full configuration report. Unlike application-level logging tools that integrate with existing permission systems, phpinfo() operates entirely outside the application's security framework.

3. Outdated Diagnostic Value

While phpinfo() shows what is configured, it does not diagnose why something is broken. It cannot trace execution flow, measure query performance, or identify memory leaks. Engineers relying solely on phpinfo() for production debugging often waste time interpreting static configuration data instead of using dynamic profiling tools.

4. Misleading "Default vs Active" Display

phpinfo() displays both the compiled-in default value and the currently active value for each directive. This dual display can confuse less experienced administrators who may adjust the wrong value or fail to understand which configuration file is overriding which setting, leading to configuration drift across environments.

5. Browser Rendering and Performance

The output of phpinfo() can be exceptionally large — frequently exceeding 100 KB of HTML and sometimes megabytes when numerous extensions are loaded. This causes slow page loads, increased bandwidth