Is there an easy way of seeing PHP info?

Is there an easy way of seeing PHP info?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Is there an easy way of seeing PHP info?

The standard workflow for inspecting your PHP environment usually involves creating a temporary file, injecting a phpinfo() call, and navigating to it via a browser. While this method works, the friction of managing that specific file—creating, editing, deleting, or worrying about leaving sensitive configuration data exposed in a public directory—is unnecessary if you have access to the command line.

On Ubuntu systems (and most Linux distributions), you can bypass the web server entirely and query PHP directly from your terminal. This approach is faster, cleaner, and eliminates the risk of accidentally exposing internal paths or settings through a browser request that might be logged or cached.

Querying PHP via the CLI

The most direct alternative to phpinfo() is using the built-in CLI flag. If you have the PHP binary available in your $PATH, you can execute the info function without creating any files:

php -i

This command outputs a comprehensive list of all loaded modules, environment variables, and configuration settings, mirroring the output of phpinfo() but formatted for terminal consumption. It is particularly useful when you need to verify which extensions are active (like pdo_mysql or gd) without relying on web server logging.

You can also target specific information by passing arguments directly to the binary:

php -i | grep 'upload_max_filesize'

This filters the massive output immediately, allowing you to check critical limits like memory usage or max execution time without scrolling through hundreds of lines. This is often more efficient than fetching a full HTML page and parsing it in a browser's developer tools.

Generating an HTML View from the Terminal

If you specifically need the visual presentation (such as for documentation or sharing with non-developers) but still want to avoid creating a persistent file on disk, you can leverage PHP's output buffering capabilities. You can pipe the CLI output through phpinfo()'s HTML mode directly to your browser using a temporary pipe or by redirecting standard output to a file that is immediately deleted after opening.

However, a more robust approach without touching the filesystem involves using a here-document combined with a shell redirection:

php -r "phpinfo();" | less

This renders the HTML in the terminal. While not as visually polished as a browser tab, it allows you to inspect the raw output structure. To actually view it in a browser without creating a file like info.php, you can use a simple shell trick that pipes the output to a temporary file and immediately opens it:

php -r "phpinfo();" | sudo tee /tmp/php_info.html && xdg-open /tmp/php_info.html

Note on Security: Using /tmp is generally safe because the directory permissions are restricted, but ensure you do not store this file permanently. The moment you finish inspecting it, the shell variable or process cleanup handles the lifecycle. Do not commit a static info.php to your repository, regardless of how temporary it seems.

Why Avoid Permanent Info Files?

Beyond the convenience of CLI tools, there is a significant security consideration regarding permanent info.php files. The default output of phpinfo() includes details about your PHP installation path, database connection details (if debug is on), and potentially exposed system paths.

If you place this file in a public directory like /var/www/html/info.php, you are creating a surface area for attackers to scan your server. Automated bots frequently crawl common filenames looking for configuration leaks. Once they find a live info.php endpoint, they can extract version numbers of your PHP runtime and extensions, helping them craft more targeted exploits.

Removing the file after inspection is good practice, but preventing it from ever being created in the first place is better. Using the CLI (php -i) keeps all configuration insights within your secure terminal session, where you control what gets logged or copied.

Finalizing Your Environment Check

For production environments running on Ubuntu, relying on php -i or specific flags like php -m (to list loaded modules) is the standard operating procedure for system administrators and lead developers. It provides the same diagnostic data as a browser-based check without the overhead of managing static files or risking accidental exposure.

If you are working within a Laravel project specifically, you might also check your local configuration via the php artisan about command, which provides a summary of your environment including PHP version, Composer version, and Laravel details, though it does not replace the full phpinfo() output for deep debugging.

Our network