How can I find the php.ini file used by the command line?

How can I find the php.ini file used by the command line?

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

Stefan Bogdanescu

Founder & Senior Architect

Locating the PHP Configuration File for the Command Line Interface

When enabling extensions like pdo_mysql in a shared hosting environment or a local setup like EasyPHP, developers often encounter a discrepancy between the configuration file they expect to edit and the one actually being loaded by the process. The core issue usually stems from mixing up the web server's PHP instance with the CLI (Command Line Interface) instance. Even if you find and modify the php.ini file in your home directory or within the EasyPHP installation folder, the CLI might be running a completely different binary that points to its own configuration file.

To resolve this, you must explicitly identify the path of the php.ini file associated with the specific PHP executable you are invoking from the terminal. The most reliable method is to use the built-in runtime configuration dump command. By executing php --ini, the interpreter prints the exact path of the currently active configuration file and lists the default paths it searches if a custom location isn't specified. This command runs independently of any web server setup, making it the definitive source of truth for CLI environments.

If you are working within an Apache or Nginx context where PHP is loaded as a module, the web server might load a different php.ini than the one used by your CLI scripts. For instance, in some shared hosting scenarios or specific local stacks, the web server uses a configuration file located in /etc/php/.../cli/php.ini for command-line tasks, while the Apache module uses /etc/php/.../apache2/php.ini. If you edit the web-specific file to enable pdo_mysql, your CLI scripts will remain unaware of this change because they are reading from a different location entirely.

When using EasyPHP or similar local development environments, the structure can be even more fragmented. These tools often bundle multiple PHP versions and separate configurations for development servers versus the CLI. Simply uncommenting the line extension=php_pdo_mysql.dll in your main configuration folder might not affect the CLI if the binary being called from the terminal is linked to a different version or configuration profile. In such cases, checking the output of php --ini inside the EasyPHP environment is crucial. You might find that the CLI is pointing to a php.ini.dist file which hasn't been copied over, or perhaps it relies on an .ini file located in a directory listed under the include_path directive rather than a single monolithic php.ini.

Another approach involves inspecting the environment variables or looking for a custom configuration file specified via the -c flag. If your CLI tool is hardcoded to use a specific config, running php -c /path/to/custom.ini will override the default behavior and apply your changes immediately. This is particularly useful when you need to test an extension without permanently modifying the system-wide configuration. However, be cautious not to mix up paths; using a path that doesn't exist or one belonging to the web server's Apache module will result in errors or ignored directives.

The decision to rely on php --ini over manual file hunting is based on the fact that PHP's runtime knows exactly which file it loaded during initialization. Relying on static directory structures can be misleading, especially in environments where virtual hosts or multiple PHP versions coexist. By trusting the interpreter's own report, you eliminate guesswork regarding version mismatches or configuration overrides.

If you are managing a production environment or a complex local stack, ensure that the extension file itself (e.g., php_pdo_mysql.dll) exists in the directory specified by the extension_dir directive within that specific CLI php.ini. It is not enough to uncomment the line; the physical DLL must be present and compatible with the architecture of the PHP binary you are invoking. This distinction between configuration syntax and runtime availability often trips up developers who assume enabling an extension is a purely text-based operation, overlooking the binary dependencies required for it to function.

Our network