DEV Community

Bert Heyman
Bert Heyman

Posted on • Edited on

1 1

How to prevent local composer upgrades from breaking your live environment

For the scope of this article, I'll assume you have (basic) experience with composer and are familiar with the way dependencies are defined.

When you want to upgrade your dependencies, composer is smart enough to take your PHP version into account: it'll only upgrade every package to compatible versions. Let's say your local environment uses PHP 7.4, but the live environment is still on 7.2. Any upgrade will work with your local 7.4 but might break on 7.2 when being pushed to live.

Telling composer about the PHP version of your live environment

{
    // requires (...)
    "config": {
        "platform": {
            "php": "8.0" // Version from the live environment
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Composer will now know about this version, and never upgrade a package to an incompatible version. So any local upgrades can be safely executed!

If your live PHP version is outdated, also consider upgrading! This will bring both performance and security improvements.

Often running into problems with different environment settings? Options exist that will create a complete container to run your application in, that will replicate the live environment - they need some setup though. (e.g. Docker)

Have you got other composer tips to share? Eager to hear about them!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay