Buy

Yo peeps! Wow, Symfony 3.3! Actually, that version number sounds kinda boring. I mean, 3.3? Really? I expect cool stuff to happen in version 3.3?

Well..... normally I'd agree! But Symfony 3.3 is special: it has some big, awesome, exciting, dinosauric changes to how you configure services. And that's why we made this crazy tutorial in the first place: to take those head on.

If you're not already comfortable with how services work in Symfony, stop, drop and roll... and go watch our Symfony Fundamentals course. Then come back.

Symfony's Backwards-Compatibility Awesomeness Promise

So, how can we upgrade to Symfony 3.3? I have no idea. No, no, no - upgrading Symfony is always boring and simple. That's because of Symfony's backwards compatibility promise: we do not break things when you upgrade a minor version, like 3.2 to 3.3. It's Symfony's secret super power. I will show you how to upgrade, but it's easy.

As always, you should totally bake cookies while watching this tutorial... and also, code along with me! Click download on this page and unzip the file. Inside, you'll find a start/ directory with the same code you see here. Open the README.md file to find poetic prose... which doubles as setup instructions.

Upgrading

Time to upgrade! Open up composer.json:

68 lines composer.json
{
... lines 2 - 15
"require": {
... line 17
"symfony/symfony": "3.1.*",
... lines 19 - 30
},
... lines 32 - 66
}

This is actually a Symfony 3.1 project, but that's no problem. I'll change the version to 3.3.0-RC1 because Symfony 3.3 has not been released yet at the time of this recording. You should use 3.3.*:

68 lines composer.json
{
... lines 2 - 15
"require": {
... line 17
"symfony/symfony": "3.3.0-RC1",
... lines 19 - 30
},
... lines 32 - 66
}

By the way, we could update other packages too, but that's optional. Often, I'll visit the Symfony Standard Edition, make sure I'm on the correct branch, and see what versions it has in its composer.json file.

For now, we'll just change the Symfony version. To upgrade, find your favorite terminal, move into the project, and run:

composer update

This will update all of your packages to the latest versions allowed in composer.json. You could also run composer update symfony/symfony to only update that package.

Then.... we wait! While Jordi and the Packagists work on our new version.

Removing trusted_proxies

It downloads the new version then... woh! An error! Occasionally, if we have a really good reason, Symfony will change something that will break your app on upgrade... but only in a huge, obvious and unavoidable way:

The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.

This says that a framework.trusted_proxies configuration was removed. Open up app/config/config.yml: there it is! Just take that out:

80 lines app/config/config.yml
... lines 1 - 11
framework:
... lines 13 - 26
trusted_hosts: ~
session:
... lines 29 - 80

The option was removed for security reasons. If you did have a value there, check out the docs to see the replacement.

Ok, even though composer update exploded, it did update our composer.lock file and download the new version. Just to be sure, I'll run composer install to make sure everything is happy:

composer install

Yes!

Enabling the WebServerBundle

Ok, start the built-in web server:

php bin/console server:run

Ahhh!

There are no commands defined in the "server" namespace

What happened to server:run? Well actually, Symfony is becoming more and more decoupled. That command now lives in its own bundle. Open app/AppKernel.php. And in the dev environment only, add $bundles[] = new WebServerBundle():

60 lines app/AppKernel.php
... lines 1 - 2
use Symfony\Bundle\WebServerBundle\WebServerBundle;
... lines 4 - 6
class AppKernel extends Kernel
{
public function registerBundles()
{
... lines 11 - 27
if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
... lines 29 - 33
$bundles[] = new WebServerBundle();
}
... lines 36 - 37
}
... lines 39 - 58
}

That bundle still comes with the symfony/symfony package, but it wasn't enabled in our project. A new Symfony 3.3 project already has this line.

Flip back to your terminal and try again:

php bin/console server:run

Got it! Find your browser and open up http://localhost:8000 to find the famous Aquanaut project that we've been working on in this Symfony series.

Okay, we're set up and we are on Symfony 3.3. But we are not yet using any of the cool, new dependency injection features. Let's fix that!

Leave a comment!

  • 2017-08-10 Diego Aguiar

    Hey Nina

    There are two options:
    - You could upgrade your PHP version to 7.1 or higher (Since you already have 7.0, this would be easy)
    - Or you could find an older release for "ocramius/proxy-manager" that fits your settings and don't break the app

    Have a nice day!

  • 2017-08-10 Nina

    Hello
    I want look result of this course and install "finish" code
    but I have error in cmd:

    c:\OpenServer\domains\finish3.3
    > composer install
    Loading composer repositories with package information
    Installing dependencies (including require-dev) from lock file
    Your requirements could not be resolved to an installable set of packages.

    Problem 1
    - Installation request for ocramius/proxy-manager 2.1.1 -> satisfiable by ocramius/proxy-manager[2.1.1].
    - ocramius/proxy-manager 2.1.1 requires php ^7.1.0 -> your PHP version (7.0.14) does not satisfy that requirement.
    Problem 2
    - ocramius/proxy-manager 2.1.1 requires php ^7.1.0 -> your PHP version (7.0.14) does not satisfy that requirement.
    - doctrine/migrations v1.5.0 requires ocramius/proxy-manager ^1.0|^2.0 -> satisfiable by ocramius/proxy-manager[2.1.1].
    - Installation request for doctrine/migrations v1.5.0 -> satisfiable by doctrine/migrations[v1.5.0].

    If I install "start" everything ok.

    I use OpenServer and
    in the Settings - PHP-7.1-x64, Apache-PHP-7-x64
    How can I to fix this problem?

  • 2017-06-12 Victor Bocharsky

    Hey Vlad,

    The "trusted_proxies" BC break was mitigated in Symfony 3.3.1 - check the https://github.com/symfony/... . It means, that now it just trigger deprecated error, but it will fail in Symfony 4.0. So if you don't use trusted_proxies in your app - you better remove it.

    Cheers!

  • 2017-06-09 Vlad

    I am using Symfony 3.3.2 and I ain't getting no error for

    trusted_proxies: ~

    Should I still remove it, or keep it?