Skip to Content

Upgrading a Symfony project from 2.6 to 3.0

Posted on    3 mins read

About this post

Symfony 3.0 has been released recently, and I wanted to upgrade my side project JourneyMonitor, which was still based on Symfony 2.6, as quickly as possible.

This post explains how I approached the upgrade, and shows which parts of the project structure and code had to be changed in order to get the project working again.

Preparing the upgrade

The code base for the project – the CONTROL component of the JourneyMonitor project – lives at https://github.com/journeymonitor/control/. As you can see in an older revision of file composer.json, it was based on Symfony 2.6, and several other dependencies. In order to find out how exactly I would have to change the versions of these dependencies, I updated the Symfony Installer to the latest version and created a new Symfony 3.0 project via symfony new foo 3.0 – it served as a reference only and was later thrown away. I compared its composer.json file with the one from my project, and changed the latter accordingly. You can view the exact changes side-by-side at Github.

Afterwards, I ran composer --with-dependencies update.

Changing the project structure

Symfony 3.0 introduces a new project directory structure. Some (but not all) of the stuff that used to live below app/ now lives either in a new folder, var/, or in bin/. I git moved app/console to bin/console, and then copied the bin/console script from the foo project to bin/console in my project. Then, I moved app/SymfonyRequirements.php to var/SymfonyRequirements.php, and moved app/cache and app/logs to var/.

The path changes had to be reflected in several files, and app/autoload.php now often takes the role of bootstrap.php.cache – see here, here, and here for example.

Fixing the code

At this point, the project did not work anymore, and what followed was the grunt work of changing the code. You can see all changes that had to be made in this side-by-side diff. Here are some of the more interesting parts:

Finding the root cause of some of the errors did cost some nerves, but was worth it. At the end, the number of changes that had to be made turned out tractable. JourneyMonitor now happily hums along on top of Symfony 3.0.

Update December 14, 2015:

Although the project was running flawlessly after the changes described above, some minor changes were still missing.

At Symfony 2.6, the tests for the AppBundle live at src/AppBundle/Tests, and they need to move to tests/AppBundle. Accordingly, the namespace of the test classes changes from AppBundle\Tests to Tests\AppBundle. See changeset c7f5f2c for details.

Another detail is that AppKernel.php no longer needs to be required explicitly, and for the production environment, one should include the bootstrap cache. See changeset 90c9190 for details.