Alines Webマガジン

phpinfophp

📅 October 29, 2026📖 Verified Publication
phpinfo.php: The Complete Security Guide & Best Practices

phpinfo.php: The Complete Security Playbook — Risks, Remediation & Best Practices

If you have ever encountered a phpinfo.php file on a web server, you are looking at one of the most common yet dangerous oversight in PHP deployment. This single file can expose your entire application stack — from database credentials to server paths — to anyone on the internet. In this guide, you will learn exactly what phpinfo.php reveals, why leaving it exposed is a critical vulnerability, and the step-by-step actions you need to take right now to secure your infrastructure.

Key Takeaways

  • phpinfo.php exposes sensitive server data, including PHP version, loaded extensions, server paths, environment variables, and often database connection details embedded in surrounding code.
  • Leaving phpinfo.php accessible in production is a high-severity vulnerability. Attackers routinely scan for it as a first-reconnaissance step.
  • The definitive fix is removal. Delete the file from production servers; use local or staging environments for debugging only.
  • If temporary visibility is required, restrict access via IP whitelisting, authentication, or .htaccess rules — but never leave it open to the public internet.
  • Audit your entire deployment pipeline to ensure no debug or diagnostic PHP files are accidentally committed to production repositories.

What Is phpinfo.php?

Origin and Purpose

The phpinfo() function is a built-in PHP language construct that outputs a comprehensive page of information about the PHP environment. When placed inside a file such as phpinfo.php, calling phpinfo(); produces an HTML report covering:

  • PHP compilation options and extensions
  • Server information and configuration (Apache, Nginx, CGI)
  • PHP version and module details
  • Environment variables and OS information
  • HTTP headers and PHP constants
  • Mail configuration and SMTP settings
  • Database driver versions (MySQLi, PDO, PostgreSQL)
  • File upload settings and memory limits
  • SSL/OpenSSL certificate and protocol support

Developers create phpinfo.php primarily as a diagnostic tool during local development and staging to verify that PHP is installed correctly and that the desired extensions are loaded. This is a legitimate and recommended practice — the problem arises when the file persists on a production server.

What Attackers See

To a developer, a phpinfo page is a useful dashboard. To an attacker, it is an intelligence goldmine. The exposed data directly enables:

  • Targeted exploit selection: Knowing the exact PHP version allows lookup of known CVEs and proof-of-concept exploits.
  • Path traversal attacks: Full server directory paths are disclosed, enabling local file inclusion (LFI) and require/include injection attacks.
  • Extension-based attacks: Loaded third-party extensions may have known vulnerabilities; the version numbers are displayed verbatim.
  • Server-side request forgery (SSRF) and RCE: Environment variable names and server architecture details reduce the effort needed to craft exploitation payloads.
  • Confidence for further enumeration: A confirmed PHP environment guides subsequent attack phases, from SQL injection to remote code execution.

Why phpinfo.php in Production Is a Critical Risk

The Threat Landscape

Automated scanners and botnets crawl the internet 24/7 for publicly accessible phpinfo pages. Tools such as Shodan, Censys, and Nmap scripts routinely fingerprint servers based on phpinfo output. A 2023 security survey found that over 14% of publicly exposed PHP servers had at least one diagnostic or informational PHP page left accessible, making this one of the most widespread misconfigurations in web hosting.

Real-World Impact Scenarios

Scenario A — Targeted RCE: An attacker discovers your phpinfo.php, identifies an outdated PHP version with a known remote code execution vulnerability, and exploits it within hours of discovery. The phpinfo page served as the initial foothold.

Scenario B — Data Exfiltration: Path disclosure from phpinfo reveals the absolute filesystem path to your web root. Combined with a local file inclusion vulnerability in your application, this enables reading sensitive files such as /etc/passwd, environment files, or database configuration.

Scenario C — Compliance Failure: Exposure of server architecture and software stack through phpinfo can trigger findings during PCI DSS, SOC 2, or HIPAA audits, resulting in remediation costs and potential penalties.

Checklist: Audit Your Server for phpinfo.php

Use this checklist to identify and address any exposed phpinfo files on your infrastructure.

Immediate Audit Steps

  • Search all web-accessible directories for files named phpinfo.php, info.php, test.php, debug.php, or pinfo.php
  • Run a recursive grep across your deployment directories: grep -r "phpinfo()" /var/www/
  • Check version control history for previously committed phpinfo files that may not have been deleted from production
  • Scan with a web vulnerability scanner (e.g., OWASP ZAP, Burp Suite) to detect hidden or renamed diagnostic pages
  • Review .htaccess and Nginx configuration for any rules that may inadvertently expose diagnostic endpoints
  • Verify that staging and development environments are not publicly accessible from the internet
  • Check CDN and reverse proxy configurations to ensure diagnostic pages are not cached or proxied to public endpoints
  • Audit CI/CD pipelines for build artifacts that may include debug files in production deployments

Remediation Steps

  • Delete all phpinfo.php files from production servers immediately
  • Remove or rename any diagnostic PHP files that are not actively needed
  • Add phpinfo to your .gitignore and establish a pre-deployment hook that blocks commits containing diagnostic functions
  • Configure your web server to return a 403 Forbidden response for any unknown or unauthorised PHP diagnostic endpoints
  • Document the removal in your incident or change management log for compliance purposes
  • Schedule recurring scans to detect accidental re-deployment of diagnostic files

Comparison: phpinfo.php Exposure vs. Secured State

Aspect Exposed phpinfo.php Secured / Removed
PHP Version Visible Yes — enables CVE matching No — version hidden
Server Paths Disclosed Yes — full absolute paths shown No — no filesystem information
Loaded Extensions Yes — all modules and versions listed No — extension list hidden
Environment Variables Yes — PATH, HOME, server variables exposed No — environment sanitised
Attack Surface High — first-step reconnaissance trivial Minimal — no diagnostic information leaked
Compliance Risk High — likely audit finding Low — aligns with hardening benchmarks
Access Control Needed None required (file is publicly accessible) No access control needed (file does not exist)

© 2026 Alines Webマガジン. All rights reserved.