Continguts
BonJanDesign

Inici · Articles

Phpinfo: What It Is and How to Use It Safely

What the phpinfo() function reveals about your server, how to use it for debugging PHP, and why you should never leave phpinfo.php exposed publicly.

Publicat
minuts de lectura
4

A `phpinfo()` page is one of the fastest ways to see what a PHP server is actually running: version, loaded extensions, configuration values, environment details and file paths, all in a single screen. It is a debugging tool, not a feature of your website, and it deserves to be treated that way.

The catch is that most `phpinfo.php` files found on live servers were never meant to be there. They were created during a quick fix or a migration and forgotten. This article explains what the page shows, what is genuinely useful in it, and how to remove or protect it without breaking anything.

What phpinfo() Actually Outputs

Calling `phpinfo()` prints a long, structured report generated by PHP itself. The top section gives the PHP version, build date, server API (FPM, Apache module, CGI), configuration file path and the operating system details. Below that you get one block per extension, each listing its version and settings.

Further down come the general configuration directives (memory limit, upload size, timezone), HTTP headers, the current environment variables and the list of included files. It is dense but readable, and it is the reference people reach for when a setting behaves differently from what the code expects.

What it does not do is tell you whether your application is well configured. It reports values, not quality. A page full of green values can still sit behind a slow database or a badly cached front end, which is a separate piece of work from server configuration.

  • PHP version and build details
  • Loaded extensions and their versions
  • php.ini location and directive values
  • Environment variables and server paths

The Real Use Cases for a phpinfo Page

The classic case is a version mismatch: a site throws a fatal error on a function that should exist, and the phpinfo page confirms whether the extension providing it is loaded. It also settles arguments about `upload_max_filesize`, `memory_limit` or `max_execution_time` in seconds rather than guesses.

A second common use is migration. When moving a site to a new host, comparing two phpinfo pages side by side shows exactly which extensions or directives differ. That comparison catches problems before they become support tickets, especially with image processing, mail and database drivers.

If you work alongside SEO and performance work, the same page tells you whether opcache is enabled and how much memory it has, which is often the cheapest speed win available on a PHP host. See SEO per a dissenyadors: conceptes bàsics que cal dominar for how technical settings feed into broader search performance.

  • Diagnosing missing extensions
  • Confirming limits before a large upload or import
  • Comparing old and new hosting environments
  • Checking opcache and memory settings

What a Public phpinfo Page Exposes

An open `phpinfo.php` reveals the exact PHP version, which is useful to anyone looking for known vulnerabilities in that release. It also exposes absolute file paths, the document root, database hostnames and sometimes environment variables that were never intended to be public.

The page also lists which security modules are active and which are not, plus the full list of enabled extensions. Put together, that is a small but real map of the server. It does not hand over passwords, but it saves an attacker time, and time is the resource they value most.

The practical rule is simple: if the URL is reachable from the public internet, assume it will eventually be found. Crawlers and scanners look for common filenames constantly, and `phpinfo.php` is near the top of the list.

How to Run It Safely

Create the file only when you need it, give it a non-obvious name, and delete it as soon as the check is done. If you need it more often, restrict access at the server level: an IP allowlist in the web server configuration, HTTP basic authentication, or a rule that only permits requests from your office range.

Never commit a phpinfo file to a repository that deploys automatically, and never leave one in a staging environment that is indexed or publicly reachable. A short deployment checklist that includes "no phpinfo files in the web root" prevents the most common leak.

On managed hosting you often do not need the file at all: control panels and CLI commands like `php -i` or `php -m` give the same information without exposing anything. If you have shell access, prefer those.

  • Use a random filename, not phpinfo.php
  • Protect with IP allowlist or basic auth
  • Delete after use; check staging too
  • Prefer CLI (php -i, php -m) when possible

Reading the Output Without Getting Lost

The page is long, so search it rather than scroll. Searching for `memory_limit`, `upload_max_filesize` or the name of an extension jumps straight to the relevant block. Each directive shows its local value and its master value, which matters when a setting is overridden per directory or per request.

Pay attention to the "Loaded Configuration File" line near the top. If it says none, PHP is running on defaults and any change you make to a php.ini file is being ignored. That single line explains a surprising number of "the setting did not apply" situations.

The "Scan this dir for additional .ini files" line shows where extra configuration is loaded from, which is where host-specific settings usually live. Reading those two lines first saves time before you touch anything else.

Typical phpinfo values and what they mean in practice
DirectiveCommon defaultTypical production rangeWhy it matters
memory_limit128M256M–512MLarge imports and page builders fail silently below this
upload_max_filesize2M20M–64MBlocks media uploads and plugin installs
post_max_size8M20M–64MMust be equal to or above upload_max_filesize
max_execution_time3060–300Long imports and bulk operations time out
opcache.enableOff (varies)OnCuts PHP execution time noticeably on repeat requests
display_errorsOn (dev)OffLeaks paths and code details to visitors

Removing It and Keeping It Gone

Deletion is the first step, but check for copies: old backups, a `test` folder, a subdomain, an inherited site you took over. Search the file tree for the string `phpinfo` and review anything it returns. A quick audit of exposed files is worth doing at the same time as a general technical review, as outlined in Com fer una auditoria SEO bàsica del teu lloc web.

If you cannot delete a file immediately because someone else depends on it, block it at the server level first. A deny rule in the web server configuration takes effect at once and can be removed cleanly later, whereas a forgotten file tends to survive for years.

Finally, add the check to your handover routine. When a project moves from development to production, a short list of files and folders that must not exist in the web root is one of the cheapest safeguards you can put in place.

22PHP 8.3+26PHP 8.218PHP 8.110PHP 8.014PHP 7.410Older
Share of PHP installs by major version (approximate, illustrative) (% of sites)
  1. phpinfo() is a diagnostic tool, not a website feature; treat the file as temporary.
  2. It exposes version, paths and environment details, so a public copy is a real risk.
  3. Search the output for specific directives instead of reading the whole page.
  4. Check the loaded configuration file path first when settings appear to be ignored.
Jordi Bonet

Dissenyador gràfic i web

Amb més de deu anys d'experiència en estudis de disseny, s'especialitza en identitat visual i disseny de interfícies. Escriu sobre processos creatius, eines i tendències del sector. El seu enfocament combina estètica i funcionalitat per a projectes de mida petita i mitjana.

Articles relacionats

03

Cookie Preferences

These are required for the site to function, such as remembering your cookie consent choice.

Not used on this site. We do not track or analyze your behavior.

Not used on this site. We do not show ads or track you for marketing.