Upgrade your legacy Symfony projects thanks to SymfonyCloud
July 8, 2020 • Published by Tugdual Saunier
If you created a new Symfony project in the last two years using Symfony 4, there are good chances that your application is using Flex. It drastically improves the experience of keeping projects up-to-date, including managing development and production environments thanks to SymfonyCloud.
However, what about applications still running Symfony 3 (or even Symfony 2)? The migration from one Symfony major version to the other is relatively easy (mainly thanks to Symfony's Backward Compatibility promise), but the migration to Flex might be more complicated as the default project tree changes, leading to infrastructure changes as well. Combine this with the migration to Symfony 4 and it becomes even more involved.
SymfonyCloud has been built from the ground up with Flex in mind. In fact, both of them work as a team with Flex enabling some SymfonyCloud features and SymfonyCloud bringing enlightenment on some edge-cases for Flex. Because of this, until now the official recommendation was to migrate to Flex before moving to SymfonyCloud.
Recently, while working on the migration of some of our very own applications (as you know «Architect's house is always crooked»), we realized that SymfonyCloud could actually help in the process of moving to Symfony 4 and Flex. A good example of that is the migration of SymfonyInsight to SymfonyCloud we performed a few weeks ago as explained by Titouan Galopin:
SymfonyInsight is an analysis platform that helps Symfony developers improve the quality and maintainability of their applications by analyzing the code of their projects automatically. It was originally developed with Symfony 2.1 and it has accumulated a lot of code in order to achieve its large features scope.
A few months ago, we started the process of migrating SymfonyInsight to SymfonyCloud as a way to iterate faster and increase our productivity, as well as reducing our costs.
We organized the migration of SymfonyInsight to SymfonyCloud in 3 main steps:
The first thing we did was migrating from Symfony 2.8 to Symfony 3.4. Doing so does require a bit of work but SymfonyInsight itself helped us a lot by showing us where we were using depreciations in our code using Upgrade Reports. The migration did not involve a project directories change, only a Symfony upgrade.
Once migrated, we could now profit from two keys features provided by Symfony 3: the cache was now mostly static, which works much better with read-only filesystems like on SymfonyCloud, and we were able to use runtime environment variables, leveraging the automatic wiring of SymfonyCloud with our services (PostgreSQL, Redis,...). We created a
develop
branch forked from our main branch and prepared the SymfonyCloud configuration there. This let us create a real environment on SymfonyCloud, allowing us to test everything in details. We still use this branch and environment as a staging environment.After a few weeks of preparation, from SymfonyCloud configuration to improvements in the code and long due refactorings, we then started the actual process of migration. We created a migration checklist in advance to avoid forgetting anything, which included:
- (the day before the migration) shortening the DNS TTL in order to decrease the duration of the DNS propagation
- disabling the scheduled tasks on the legacy infrastructure to avoid changing the database while we were migrating it
- enabling the maintenance mode both on the SymfonyCloud and the legacy infrastructures
- waiting for consumers to finish processing current messages and stopping them, also to avoid changing the database during the migration
- actually cloning the database to SymfonyCloud
- switching the DNS to target the new infrastructure
- enabling consumers and scheduled tasks on the new infrastructure
- disabling the maintenance on the new infrastructure
This maintenance lasted about 9 hours in order to migrate our 460G database to SymfonyCloud.
In the end, the migration was a success. We now deploy much more often (sometimes several times a day) and we decreased our cost by 50% from our legacy infrastructure on AWS.
Today, we released the final update to SymfonyCloud in order to smooth the experience running Symfony 2 or 3 applications on SymfonyCloud and assist you in the process of migrating to Symfony 4 and Flex.
Start your migration today by reading the following guide: Upgrading Existing Applications to Symfony Flex.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.