Upgrading to Symfony 4.4

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

To upgrade from Symfony 4.3 to 4.4 - that's a "minor" version upgrade - we need to change the extra.symfony.require value to 4.4.* - done! - and update each Symfony package version to that same value.

Updating Versions of Individual Symfony Packages

Let's get to work! I'll start with symfony/asset: change it to 4.4.*. Copy that and start repeating it:

104 lines composer.json
{
... lines 2 - 3
"require": {
... lines 5 - 20
"symfony/asset": "4.4.*",
"symfony/console": "4.4.*",
... line 23
"symfony/form": "4.4.*",
"symfony/framework-bundle": "4.4.*",
"symfony/mailer": "4.4.*",
"symfony/messenger": "4.4.*",
... line 28
"symfony/security-bundle": "4.4.*",
"symfony/sendgrid-mailer": "4.4.*",
... line 31
"symfony/twig-bundle": "4.4.*",
... line 33
"symfony/validator": "4.4.*",
"symfony/web-server-bundle": "4.4.*",
... line 36
"symfony/yaml": "4.4.*",
... lines 38 - 40
},
... lines 42 - 95
"extra": {
"symfony": {
... lines 98 - 99
"require": "4.4.*"
}
}
}

I will skip a few packages that start with symfony/ because they are not part of the main Symfony repository - like symfony/flex:

104 lines composer.json
{
... lines 2 - 3
"require": {
... lines 5 - 22
"symfony/flex": "^1.0",
... lines 24 - 40
},
... lines 42 - 102
}

These follow their own release schedules... so they usually have a version that's very different than everything else.

All "packs" - those are the, sort of, "fake" packages that just require other packages for convenience - are another example:

104 lines composer.json
{
... lines 2 - 3
"require": {
... lines 5 - 27
"symfony/orm-pack": "^1.0",
... lines 29 - 30
"symfony/serializer-pack": "^1.0",
... line 32
"symfony/twig-pack": "^1.0",
... lines 34 - 40
},
... lines 42 - 102
}

These usually allow pretty much any version of the libraries inside of them - so any Symfony packages will update correctly. If you want more control over the versions, remember that you can run:

composer unpack symfony/orm-pack

When you do that, Flex will remove this line and replace it with the individual packages so you can manage their versions. That's not required, but also not a bad idea.

WebpackEncoreBundle is another example of a package that isn't part of the main repository - you can see that its version is totally different:

104 lines composer.json
{
... lines 2 - 3
"require": {
... lines 5 - 35
"symfony/webpack-encore-bundle": "^1.4",
... lines 37 - 40
},
... lines 42 - 102
}

Don't forget to also check the require-dev section: there are a bunch here:

104 lines composer.json
{
... lines 2 - 41
"require-dev": {
... lines 43 - 45
"symfony/browser-kit": "4.4.*",
"symfony/debug-bundle": "4.4.*",
"symfony/dotenv": "4.4.*",
... lines 49 - 50
"symfony/phpunit-bridge": "4.4.*",
... line 52
"symfony/var-dumper": "4.4.*"
},
... lines 55 - 102
}

Including symfony/debug-bundle, which has a funny-looking version because I unpacked it from a debug-pack in one of our courses. And both MakerBundle and MonologBundle are not in the main repository:

104 lines composer.json
{
... lines 2 - 41
"require-dev": {
... lines 43 - 48
"symfony/maker-bundle": "^1.0",
"symfony/monolog-bundle": "^3.0",
... lines 51 - 53
},
... lines 55 - 102
}

If you're not sure, you can search Packagist.org for symfony/symfony. That package lists all of the packages that make up this "main" repository I keep talking about.

Update phpunit-bridge, leave the profile-pack version and update var-dumper:

104 lines composer.json
{
... lines 2 - 41
"require-dev": {
... lines 43 - 50
"symfony/phpunit-bridge": "4.4.*",
... line 52
"symfony/var-dumper": "4.4.*"
},
... lines 55 - 102
}

Perfect! We have 4.4.* everywhere up here and 4.4.* for extra.symfony.require so that everything matches and we get that performance boost in Composer.

Let's do this! Find your terminal and run:

composer update "symfony/*"

And... yea! It's upgrading the last few libraries that were previously locked to 4.3. Congratulations! You just upgraded all Symfony packages to 4.4.

Fixing some require-dev Packages

Before we move on, I noticed a small problem in composer.json: the symfony/dotenv package is in my require-dev section:

104 lines composer.json
{
... lines 2 - 41
"require-dev": {
... lines 43 - 47
"symfony/dotenv": "4.4.*",
... lines 49 - 53
},
... lines 55 - 102
}

When we put something in require-dev, we're saying:

This package is not needed when I run my code on production.

It was true that when Symfony 4.0 was released, the DotEnv component was used in the development environment only - as a way to help set environment variables more easily. That's not true anymore: Symfony apps now always load the .env files.

The symfony/monolog-bundle package - which gives us the logger service - should also live under require - along with its supporting package: easy-log-handler:

104 lines composer.json
{
... lines 2 - 41
"require-dev": {
... line 43
"easycorp/easy-log-handler": "^1.0.2",
... lines 45 - 49
"symfony/monolog-bundle": "^3.0",
... lines 51 - 53
},
... lines 55 - 102
}

Logging is something we always want.

Let's fix these. Copy the symfony/dotenv package name, find your terminal, and remove these three packages:

composer remove --dev symfony/dotenv symfony/monolog-bundle easycorp/easy-log-handler

An easy way to move a package from require-dev to require and make sure that Composer notices, is to remove the package and re-add it.

When we do that... our code explodes! No problem: our app totally needs the DotEnv component... so it's temporarily freaking out. You'll also notice that, if you run:

git status

Removing these packages also removed their recipes. Re-add the libraries by using that same command, but replacing remove with require and getting rid of the --dev flag:

composer require symfony/dotenv symfony/monolog-bundle easycorp/easy-log-handler

Tip

The easycorp/easy-log-handler package is abandoned, so it's probably even better to remove it from this list and leave it out of your app

This should add those back under the require section - yep, here is one - and it will reinstall the latest version of their recipes... which means that the recipe could be slightly newer than the one we had before:

104 lines composer.json
{
... lines 2 - 3
"require": {
... lines 5 - 7
"easycorp/easy-log-handler": "^1.0",
... lines 9 - 23
"symfony/dotenv": "4.4.*",
... lines 25 - 29
"symfony/monolog-bundle": "^3.5",
... lines 31 - 43
},
... lines 45 - 102
}

This is... accidentally... the first example of upgrading a recipe. Run:

git status

Cool. Should we commit all of these changes? Not so fast. When a recipe is updated, you need to selectively add each change. Let's learn how next.

Leave a comment!

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.3.0",
        "ext-iconv": "*",
        "antishov/doctrine-extensions-bundle": "^1.4", // v1.4.2
        "aws/aws-sdk-php": "^3.87", // 3.110.11
        "doctrine/doctrine-bundle": "^2.0", // 2.0.6
        "doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // 2.1.2
        "doctrine/orm": "^2.5.11", // v2.7.2
        "easycorp/easy-log-handler": "^1.0", // v1.0.9
        "http-interop/http-factory-guzzle": "^1.0", // 1.0.0
        "knplabs/knp-markdown-bundle": "^1.7", // 1.8.1
        "knplabs/knp-paginator-bundle": "^5.0", // v5.0.0
        "knplabs/knp-snappy-bundle": "^1.6", // v1.7.0
        "knplabs/knp-time-bundle": "^1.8", // v1.11.0
        "league/flysystem-aws-s3-v3": "^1.0", // 1.0.23
        "league/flysystem-cached-adapter": "^1.0", // 1.0.9
        "league/html-to-markdown": "^4.8", // 4.8.2
        "liip/imagine-bundle": "^2.1", // 2.3.0
        "nexylan/slack-bundle": "^2.1", // v2.2.1
        "oneup/flysystem-bundle": "^3.0", // 3.3.0
        "php-http/guzzle6-adapter": "^2.0", // v2.0.1
        "sensio/framework-extra-bundle": "^5.1", // v5.5.3
        "symfony/asset": "5.0.*", // v5.0.2
        "symfony/console": "5.0.*", // v5.0.2
        "symfony/dotenv": "5.0.*", // v5.0.2
        "symfony/flex": "^1.0", // v1.6.2
        "symfony/form": "5.0.*", // v5.0.2
        "symfony/framework-bundle": "5.0.*", // v5.0.2
        "symfony/mailer": "5.0.*", // v5.0.2
        "symfony/messenger": "5.0.*", // v5.0.2
        "symfony/monolog-bundle": "^3.5", // v3.5.0
        "symfony/security-bundle": "5.0.*", // v5.0.2
        "symfony/sendgrid-mailer": "5.0.*", // v5.0.2
        "symfony/serializer-pack": "^1.0", // v1.0.2
        "symfony/twig-bundle": "5.0.*", // v5.0.2
        "symfony/twig-pack": "^1.0", // v1.0.0
        "symfony/validator": "5.0.*", // v5.0.2
        "symfony/webpack-encore-bundle": "^1.4", // v1.7.2
        "symfony/yaml": "5.0.*", // v5.0.2
        "twig/cssinliner-extra": "^2.12", // v2.12.0
        "twig/extensions": "^1.5", // v1.5.4
        "twig/inky-extra": "^2.12" // v2.12.0
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.0", // 3.3.0
        "fzaninotto/faker": "^1.7", // v1.8.0
        "symfony/browser-kit": "5.0.*", // v5.0.2
        "symfony/debug-bundle": "5.0.*", // v5.0.2
        "symfony/maker-bundle": "^1.0", // v1.14.3
        "symfony/phpunit-bridge": "5.0.*", // v5.0.2
        "symfony/profiler-pack": "^1.0", // v1.0.4
        "symfony/var-dumper": "5.0.*" // v5.0.2
    }
}