Upgrading to Symfony 3!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
We are now finally ready to upgrade our project to Symfony 3. How do we do that? It's a simple, 2 step process.
First, in composer.json
change the symfony/symfony
key, to 3.0.*
:
{ | |
// ... lines 2 - 12 | |
"require": { | |
// ... lines 14 - 30 | |
"symfony/symfony" : "3.0.*", | |
// ... line 32 | |
}, | |
// ... lines 34 - 64 | |
} |
Or, if you're upgrading to any even new version, use that - like 3.1.*
.
Second, run composer update
. This time, run it with no arguments:
composer update
We technically only need to upgrade the symfony/symfony
package, but since
so many libraries depend on this, it's pretty tough to only update Symfony.
If you're worried about too much stuff upgrading, make sure you version constraints
in composer.json
are really tight.
But as we wait for this: I have a surprise! This will almost definitely not work.
Upgrading other Libraries
And just as I say that, huge error! Oh boy, these are a pain to read at first.
But if you follow down, eventually you'll find the problem. Ah, there it is: the
installation for sensio/distribution-bundle
requires symfony/process
at version
2.2. In normal English, Composer is saying:
Yo! Your version of
sensio/distribution-bundle
in composer.json needssymfony/process
2.2. You probably need to upgrade the distribution bundle to a new version that works withsymfony/process
version 3.
This means we need to update the version for sensio/distribution-bundle
in composer.json
to something higher. In these cases, I like to open Packagist
and search for symfony/framework-standard-edition
. This is the project you get
when you first download Symfony. We can cheat by looking at its composer.json
versions.
Let's see what it looks like at the latest 3.0 version - 3.0.8. Ok - this project
requires sensio/distribution-bundle
at version ^5.0
. Open our composer.json
and change it to match: ^5.0
:
{ | |
// ... lines 2 - 12 | |
"require": { | |
// ... lines 14 - 25 | |
"sensio/distribution-bundle" : "^5.0", | |
// ... lines 27 - 32 | |
}, | |
// ... lines 34 - 64 | |
} |
That's it! Run Composer update again:
composer update
We may get another error about another library, but this is the process: run
$ composer update
, find the problematic package, update its version and repeat.
Yep: another problem. This time it's from sensio/generator-bundle
. Go back to
Packagist: the version in the Standard Edition is ^3.0
. Update our composer.json
:
{ | |
// ... lines 2 - 33 | |
"require-dev": { | |
"sensio/generator-bundle": "^3.0" | |
}, | |
// ... lines 37 - 64 | |
} |
And run Composer again:
composer update
If you get an error from a package that's not part of the Standard Edition, then you'll need to go look up that library in Packagist or on GitHub to find a version that's 3.0-compatible. That's exactly what we did with AsseticBundle.
Et voila! We just downloaded Symfony 3.0.8.
Well, let's see if it works! Refresh! Yes! Everything looks great: a major framework upgrade without breaking your code! Give yourself a congrats. And then, don't forget to run your tests and QA your site to make sure we didn't missing anything.
All right, guys, if you have any questions, let me know.
Seeya next time!
One question: could we do this on easier way? for example:
1) install sf 3 (new folder)
2) copy src (sf 2.7) folder to new symfony 3 (maybe cache and logs files if we want)
3) fix only our code
4) if works fine, move to prod server
On this way we can avoid symfony core and external bundles upgrade issues and focus only on our code (AppBundle).
Is this good idea :) ?