Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Upgrading to Symfony 3.3!

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.

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:

Tip

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:

... 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():

... 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!

6
Login or Register to join the conversation

Hello , i am trying to run this project but i keep getting this erreur and some times o others like the cache problem :

PHP Fatal error: Declaration of DoctrineORMEntityManager_000000005d3465c800000000622fd46ee1c521f0bc53aec1c406e6390
bc9e21a::getProxyInitializer() must be compatible with ProxyManager\Proxy\LazyLoadingInterface::getProxyInitializer
(): ?Closure in C:\start\var\cache\dev\appDevDebugProjectContainer.php.

any help please

Php version : 7.4.*

Reply

Hey Hamza Aboulas!

Hmmm. I think overall the problem is going to be that Symfony 3.3 is old, and was never designed to work even on PHP 7.0 (let alone 7.4). At the very least, you would need to update the dependencies as much as you can (e.g. composer update), but even that might not help: the dependencies might just be too old to work on PHP 7.4. I have a feeling you already tried this, because after running composer update on the code, I get the same error as you :).

Sorry I can't offer something more helpful! I think Symfony 3.3 is just too old to run in PHP 7 at this point :). Hopefully you can still read/watch the parts of the tutorial that are interesting to you to get what you need. If you have any questions, let us know!

Cheers!

Reply
Claire S. Avatar
Claire S. Avatar Claire S. | posted 4 years ago

Hi :)
I was wondering if you could point me in the right direction with a problem I'm having. I've upgraded to 3.4 wooo. However registered users from my 2.8 application can't login but if i create a new user and login it works fine. Any hints/tip ?

Cheers
Claire

Reply

Hey Claire,

Oh, looks like in this upgrade you changed your encoder algorithm, see "security.encoders.UserInterface.algorithm" in your app/config/security.yml. You can't just change it because all old passwords will be invalid anymore as they will be checked with a new algorithm. Revert back the original value and it should work for old passwords after upgrade

Cheers!

Reply
Default user avatar

If your application's document root differs from the standard directory layout, you have to pass the correct location using the --docroot option:


php bin/console server:start --docroot=public_html
Reply

Hey Stan,

We suppose our users download the start code and recommend this way to code with us, but it may be useful for someone, thanks for sharing this little-known fact about Symfony web server.

Cheers!

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.3.0-RC1", // v3.3.0-RC1
        "doctrine/orm": "^2.5", // 2.7.5
        "doctrine/doctrine-bundle": "^1.6", // 1.10.3
        "doctrine/doctrine-cache-bundle": "^1.2", // 1.3.5
        "symfony/swiftmailer-bundle": "^2.3", // v2.6.7
        "symfony/monolog-bundle": "^3.1", // v3.2.0
        "symfony/polyfill-apcu": "^1.0", // v1.23.0
        "sensio/distribution-bundle": "^5.0", // v5.0.25
        "sensio/framework-extra-bundle": "^3.0.2", // v3.0.29
        "incenteev/composer-parameter-handler": "^2.0", // v2.1.4
        "composer/package-versions-deprecated": "^1.11", // 1.11.99.4
        "knplabs/knp-markdown-bundle": "^1.4", // 1.7.1
        "doctrine/doctrine-migrations-bundle": "^1.1", // v1.3.2
        "stof/doctrine-extensions-bundle": "^1.2" // v1.3.0
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0", // v3.1.7
        "symfony/phpunit-bridge": "^3.0", // v3.4.47
        "nelmio/alice": "^2.1", // v2.3.6
        "doctrine/doctrine-fixtures-bundle": "^2.3" // v2.4.1
    }
}