How to change the path to php.ini in PHP CLI version

How to change the path to php.ini in PHP CLI version

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

Stefan Bogdanescu

Founder & Senior Architect

How to change the path to php.ini in PHP CLI version

When developing on Windows environments like WAMP, a common source of friction is the divergence between your web server's PHP configuration and your Command Line Interface (CLI) settings. The output of php --ini often reveals this split immediately. In many standard setups, the CLI tool loads its configuration from a directory distinct from where Apache serves the application.

Consider a scenario where php --ini reports that the Loaded Configuration File is located at C:\wamp\bin\php\php5.3.8\php.ini. Meanwhile, your web server running under Apache is utilizing a completely different file, typically found at C:\wamp\bin\apache\Apache2.2.21\bin\php.ini. This dual-configuration state is frequent on local development stacks but leads to inconsistency. If you adjust error reporting levels, timezone settings, or memory limits in the web configuration but forget the CLI version, your scripts will behave differently depending on how they are invoked.

To align these environments, you need to modify the path used by the CLI interpreter. The most direct method is through the command-line arguments provided when invoking PHP. You can force the CLI to read a specific configuration file by passing the -c flag followed by the absolute path to your desired php.ini. For example, if you want the CLI to adopt the web server's configuration located in the Apache bin directory, you would execute your scripts with:

php -c C:\wamp\bin\apache\Apache2.2.21\bin\php.ini your_script.php

This approach is functionally identical to changing the default php.ini but offers a crucial advantage: it requires no changes to system files or registry entries. You retain the ability to use different configuration profiles for different tasks simply by adjusting the flag. This flexibility is particularly useful if you need specific extensions enabled only for CLI tools while keeping the web server lightweight, or vice versa.

However, relying on command-line flags can become cumbersome if you have a suite of scripts or an IDE that automatically invokes PHP without passing arguments. In such cases, you must explicitly configure the environment to persist this setting. The most robust solution involves modifying the php.ini file within the CLI installation directory itself. You can add the directive:

; Load configuration from Apache bin directory
include_path = "C:\wamp\bin\apache\Apache2.2.21\bin"

While include_path is primarily for finding extensions, some environments respect a custom path via environment variables or specific registry keys depending on the PHP version and build. A more reliable alternative for WAMP users who wish to merge configurations without maintaining two separate files entirely is to symlink or copy the web server's php.ini into the CLI directory, then edit it to remove any conflicting definitions.

It is important to note that merging these files requires care. The CLI version might rely on specific extensions located in its own ext folder, which may not be present in the Apache bin directory. If you simply overwrite the CLI php.ini with the web version, you risk missing out on CLI-specific modules or causing fatal errors if extension paths do not match.

For projects using frameworks like Laravel, consistency is paramount. Discrepancies in configuration can lead to obscure errors where a feature works on the server but fails during local artisan commands. If you are managing a complex setup involving multiple PHP versions via tools like XAMPP or WAMP, ensuring that your CLI arguments explicitly point to the correct php.ini prevents these silent failures.

Ultimately, while maintaining two separate configuration files is technically sound and isolates concerns, it introduces unnecessary overhead for local development. By leveraging the -c flag or carefully merging configurations, you ensure that the logic governing your application remains uniform regardless of the execution context.

Our network