Skip to content

/flags/php/php-ini-show-loaded-config

php --ini: show which php.ini file is loaded

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
PHP
command
php
flag
--ini
default
-
since
PHP 5.2.3

php --ini prints where the PHP command-line interpreter looks for php.ini, which file it actually loaded, and which additional .ini files it parsed from the scan directory, then exits. It is the first command to run when a setting you changed "does not work": often the file you edited is not the one PHP loads, or the web server uses a different file than the CLI.

Output

The example uses PHP 8.4 compiled to WebAssembly (php-wasm, from the WordPress Playground project), which ships its own php.ini:

bash
npm init -y >/dev/null
npm install --silent --no-audit --no-fund @php-wasm/node@3.1.56 @php-wasm/universal@3.1.56 >/dev/null 2>&1
cat > php.mjs <<'JS'
// Minimal "php" command: copies *.php files into the virtual file system and runs the CLI
import fs from "node:fs";
import { PHP } from "@php-wasm/universal";
import { loadNodeRuntime } from "@php-wasm/node";
const php = new PHP(await loadNodeRuntime("8.4", { emscriptenOptions: { processId: 1 } }));
php.mkdir("/app");
for (const f of fs.readdirSync(".").filter((f) => f.endsWith(".php"))) php.writeFile(`/app/${f}`, fs.readFileSync(f));
php.chdir("/app");
const r = await php.cli(["php", ...process.argv.slice(2)]);
process.stdout.write(await r.stdoutText);
process.stdout.write(await r.stderrText);
process.exit(await r.exitCode);
JS
node php.mjs --ini
echo "== from code"
node php.mjs -r 'var_dump(php_ini_loaded_file(), php_ini_scanned_files());'

Output

Configuration File (php.ini) Path: /usr/local/etc
Loaded Configuration File:         /internal/shared/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)
== from code
string(24) "/internal/shared/php.ini"
bool(false)

The four lines are the same on every platform; only the paths differ. On a Debian or Ubuntu package install the CLI typically reports /etc/php/8.x/cli/php.ini and a scan directory /etc/php/8.x/cli/conf.d with one file per extension; on Windows the path is usually next to php.exe.

The four lines

LineMeaning
Configuration File (php.ini) PathDirectory compiled into PHP (or set with PHPRC) where php.ini is searched
Loaded Configuration FileThe php.ini actually used, or (none)
Scan for additional .ini files inScan directory (PHP_INI_SCAN_DIR or the compiled default), or (none)
Additional .ini files parsedEvery extra file loaded from that directory, in order

How PHP finds php.ini

  1. The -c <path> option (file or directory) on the command line.
  2. The PHPRC environment variable.
  3. The current working directory (except for the CLI SAPI).
  4. The directory of the PHP binary on Windows, and the compiled-in path (--with-config-file-path).

Then every *.ini file in the scan directory is read in alphabetical order, so a later file can override an earlier one. -n disables php.ini completely, which is useful to check whether a problem comes from the configuration.

bash
php --ini                                 # which files are loaded
php -i | grep -i 'memory_limit'           # effective value (phpinfo in text form)
php -r 'echo ini_get("memory_limit");'    # one value
php -c /path/to/custom.ini script.php     # use another php.ini for one run
php -d memory_limit=1G script.php         # override one directive

-d is covered in php -d; to check which extensions are loaded by those files, use php -m.

CLI versus web server

The CLI and PHP-FPM (or Apache mod_php) are separate SAPIs and usually read different php.ini files. php --ini describes only the CLI. For the web server, create a temporary page with <?php phpinfo(); and look at "Loaded Configuration File", or run php-fpm -i | grep 'Loaded Configuration' for the FPM binary. Settings such as upload_max_filesize must be changed in the web server's file and need a reload.

FAQ

Why does my change in php.ini have no effect?

Usually because you edited a different file than the one PHP loads. php --ini shows the CLI's file; the web server's PHP (FPM, Apache) often loads another one, which phpinfo() in a web page reveals. Also restart PHP-FPM or Apache after editing.

What does Loaded Configuration File: (none) mean?

PHP did not find a php.ini in the configured path, so it runs with built-in defaults plus any scanned .ini files. Copy php.ini-development or php.ini-production from the PHP distribution to the path shown on the first line.

How do I find the php.ini in code?

php_ini_loaded_file() returns the path of the loaded php.ini or false, and php_ini_scanned_files() returns the comma-separated list of additional .ini files or false.

Sources