Baking --ignore-platform-reqs Into Composer Config
When your local PHP environment diverges from what a dependency requires, Composer will stop execution immediately unless you intervene. This is standard behavior designed to prevent installing packages that are incompatible with your runtime. However, in scenarios where the application logic relies on a Docker container for the actual executionâwhile development happens on a host with a different versionâthe strict checks become an annoyance rather than a safeguard.
You might find yourself frequently typing composer install --ignore-platform-reqs to bypass these errors. While this works, it is easy to forget the flag, leading to inconsistent workflow interruptions. Since your actual runtime environment inside Docker satisfies the requirements regardless of your host's version, the local check feels like noise. The goal is to make the CLI behave as if the flag were always present without manually appending it every time.
Composer supports persistent configuration through its own config system, which allows you to define default options that apply to all commands executed in a specific context. You can configure this globally for your user or locally within a project directory. To achieve the behavior you are looking for, you need to add the platform requirements flag to the config.json file.
First, identify where Composer stores its configuration. It typically looks for ~/.composer/config.json for global settings or composer.json in the root of your project. You can verify the active config file by running composer config --absolute. To modify it globally, create a new JSON file if it doesn't exist using:
mkdir -p ~/.composer
echo '{ "config": { "platform-check": false } }' > ~/.composer/config.json
Alternatively, you can use the command-line interface to set the configuration key directly without creating a file manually:
composer config platform-check false
This command sets the platform-check key to false. When this value is set to false, Composer effectively treats all commands as if they were invoked with the --ignore-platform-reqs flag. This applies to install, update, and any other command that checks PHP version compatibility.
There are distinct trade-offs to consider when disabling platform checks. The primary benefit is workflow smoothness; you can install dependencies on a host machine running a different PHP version without friction. However, this masks potential incompatibilities during local development. If you write code assuming the current PHP version and then deploy to an environment where the check was previously enforced (or if someone else runs composer install without the config), you might encounter runtime errors that were hidden locally.
Furthermore, simply ignoring platform requirements does not mean your application will run correctly on a different version. It only prevents Composer from aborting the installation process. If your code relies on specific features introduced in PHP 5.5 but your local machine has PHP 7.0.3 (or vice versa), you may face subtle bugs or deprecated function warnings that are not caught by the static analysis of the dependency checker.
If you prefer to keep this setting isolated to a specific project rather than affecting all Composer operations system-wide, run the same command inside the project directory:
composer config platform-check false
This writes the configuration specifically for that repository. It ensures that team members working on the same codebase will experience the same environment consistency regarding dependency installation, even if their local PHP versions differ.
Ultimately, configuring platform-check to false is a deliberate decision to prioritize development velocity over strict environment validation at the install phase. As long as you are aware that your Docker container defines the true runtime constraints, this configuration allows you to focus on code rather than version mismatches during the setup process.