PHP error guide
PHP CLI loads a different php.ini: meaning and fix
Error summary
Inspect php --ini for the exact binary and place CLI-specific settings in its scan tree instead of editing the FPM configuration.
What it means
Inspect php --ini for the exact binary and place CLI-specific settings in its scan tree instead of editing the FPM configuration.
What the error means
PHP CLI and the web SAPI use separate configuration files or scanned directories, so extensions and limits can differ.
Why PHP produces it
Each SAPI discovers configuration independently, and multiple PHP versions commonly have distinct cli and fpm ini trees.
PHP version notes
The behavior described for PHP CLI loads a different php.ini applies to PHP 7.4–8.4 unless a narrower version is stated; exact wording can vary by SAPI and patch release.
Most common causes
- The operator edits /fpm/php.ini while testing CLI.
- A PHPRC or PHP_INI_SCAN_DIR environment variable redirects discovery.
- The shell resolves a different PHP version than the web pool.
Minimal examples
BAD — reproduces the problem
edit /etc/php/8.3/fpm/php.ini
php script.php
FIXED — safer pattern
/usr/bin/php8.3 --ini
/usr/bin/php8.3 script.php
Step-by-step diagnosis
- Run the exact binary with --ini and -i.
- Compare PHP_BINARY, PHP_VERSION, and loaded_ini_file between CLI and web.
- Inspect PHPRC and PHP_INI_SCAN_DIR for the invoking user.
Fixes
Change the configuration for the affected SAPI
Use a CLI-specific ini fragment or explicit -c path after confirming scope.
/usr/bin/php8.3 --ini
/usr/bin/php8.3 -c /srv/app/config/php-cli.ini bin/task.php
Common mistakes when fixing it
- Restarting FPM for a CLI-only ini change.
- Editing every ini file until behavior changes.
- Ignoring additional scanned ini files.
How to prevent it
- Document per-SAPI configuration paths.
- Pin CLI binaries in scheduled jobs.
- Add a diagnostic command that records loaded_ini_file.
Web server / environment notes
cli, fpm, linux. Configuration must be compared using the same binary and SAPI as the failure.
Tags: cli,fpm,linux