Limits of Composer config.platform for deployment PHP targeting
0 reputation · 03 Mar 2023, 20:26 UTC
0 reputation · 03 Mar 2023, 20:26 UTC
Declare the deployment PHP version in composer.json using config.platform so Composer resolves dependencies for the target runtime rather than the machine running Composer. The local resolution host and deployment host may run different PHP versions and extension sets.
config.platform changes only the platform assumed during dependency resolution. It does not install or emulate a runtime, and it does not guarantee that application code works on the target. The unresolved decision is whether to encode a fixed deployment version, the oldest supported version, or no override at all. An inaccurate override can produce a dependency set unsuitable for the actual host.
Which platform value should composer.json encode when a project supports multiple deployment targets, and what verification confirms that the resolved composer.lock matches the intended runtime?
Do not encode one fixed platform value in composer.json when deployment targets run different PHP versions or extension sets. Use either a separate composer.lock per target, resolved with config.platform set to that target, or encode only the lowest common denominator: the oldest PHP version and the intersection of extensions available on every target. A single override newer than the oldest target can select dependencies that fail at runtime; an older override can unnecessarily restrict the dependency set.
config.platform only changes the PHP version and extension versions Composer assumes while solving. It does not install PHP, emulate a runtime, or validate application code. composer.lock records what was resolved under that assumed platform, not what the deployment host actually provides.
php -v and php -m on the target or an identical container.config.platform.php and config.platform.ext-* to match that target, then run composer install or composer update.php -v and php -m output.Run composer install in a container matching each target PHP version with config.platform set to that target, then confirm the resolved platform requirements match php -v and php -m on that host. Treat any mismatch as a deployment blocker. Confirm behavior against your installed Composer release, because platform checking and lock metadata can differ between releases.
Missing diagnostic detail: do all deployment targets share the same PHP minor version and extension intersection? This determines whether a single lock is sufficient or whether per-target locks are required.
Editorial note: verify this guidance against your installed Composer release before deploying to production.
Use comments to ask for clarification. Post a solution as an answer.
37,275 reputation · 03 Mar 2023, 21:00 UTC
A single config.platform.php value drives one dependency resolution, so it cannot represent several deployment runtimes at once. The resolved packages are tied to that declared platform, not automatically to the deployment host. A useful follow-up is to generate and test a separate composer.lock per supported PHP version in CI, then verify with composer show --platform inside a target-matching container before deploying. Declare a full release such as 8.1.2; a major.minor-only value can leave patch resolution ambiguous.