Content · Web Development · PHP

Debugging Differences Between PHP CLI and PHP-FPM

CLI and FPM may load different PHP configurations, extensions and environment variables despite running the same source code.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

CLI and FPM may load different PHP configurations, extensions and environment variables despite running the same source code.

What It Does


Show the CLI SAPI and active configuration. Inspect FPM or the web SAPI using a private development route.

Requirements and Compatibility


Use a supported PHP runtime and install any third-party tool or extension explicitly shown in the examples. Commands should be run from the project root unless stated otherwise.

Syntax, Inputs and Results


The examples separate configuration, the smallest working operation and a realistic follow-up task. Adapt file paths and dependency versions to your own project.

Example 1: Basic Use


Show the CLI SAPI and active configuration.

php --ini
php -r 'echo PHP_SAPI, " | " , php_ini_loaded_file(), PHP_EOL;'

Example 2: Another Case


Inspect FPM or the web SAPI using a private development route.

<?php
header('Content-Type: text/plain');
echo PHP_SAPI, PHP_EOL;
echo php_ini_loaded_file() ?: 'No ini';
echo PHP_EOL, getcwd();

Practical Example


Compare extensions and resource limits with the web output.

php -m | sort
php -r 'echo ini_get("memory_limit"), PHP_EOL;'

For production, apply the compatibility and edge-case limits described below.

Important Behavior and Edge Cases


Check each active SAPI separately rather than assuming CLI settings control web requests.

Comparison with Related Functions and Tools


SubjectKey difference
Step debugging vs profilingStep debugging pauses individual statements; profiling records aggregate runtime cost.

Common Beginner Mistakes


MistakeCorrect approach
Enabling the debugger for every production requestUse controlled triggers and disable development modes in production.
Skipping the prerequisite of this specific workflowInstall or configure the named tool and confirm the example can actually run.
Ignoring edge conditionsCheck each active SAPI separately rather than assuming CLI settings control web requests.

Key Takeaways


  • CLI and FPM may load different PHP configurations, extensions and environment variables despite running the same source code.
  • Check each active SAPI separately rather than assuming CLI settings control web requests.
  • Keep application configuration, source code and validation tests under version control.

Use these examples as a starting point, then validate the result with the actual PHP build, dependencies and inputs used by your application.

Share this resourceSend this page to someone who may find it useful.