13th December 2019

Upgrading Yii 1 web applications

We're coming to the end of our latest Yii 1 upgrade project, one of our largest Yii 1 migrations to date - and a good time to reflect on the challenges and opportunities that updating from Yii 1 brings.
PHP Framework Migration

Migrating from Yii 1

We've been busy through November and December working on our latest Yii 1 upgrade project, one of our largest Yii 1 migrations to date. We're nearing the end of this piece of work, and we've been reflecting on the challenges - and opportunities - that upgrading from the Yii 1 PHP framework provides.

Yii Framework Logo

Our client's internal operations web application, built on Yii 1, has been in use since 2014. Over that time it's expanded with new features and become an essential part of their business operations.

However, with the Yii 1 framework becoming end-of-life on 31st December 2020, it became clear that an upgrade to Yii 2 was essential to maintain the application's quality, reliability and security. Furthermore, with a backlog of new features waiting to be built, it would have been wasteful to build these in Yii 1 only to be out-of-date within 12 months.

So over the last few weeks we've been deep in PHP code, rebuilding the application into Yii 2.

While this process is slow and painstaking - it's given us the opportunity to give the app a huge spring clean, with optimisation, refactoring and the implementation of modern web techniques.

The challenges

What to upgrade to?

The first decision in any Yii1 migration project is of course which approach to take. Upgrade to Yii 2? Laravel? How about forget the PHP frameworks and rebuild the app using serverless architecure?

There's no easy way around the fact that for a migration to Yii 2, about 4 out of every 10 lines of code will need to change to match the new Yii 2 framework format. To migrate to another PHP framework like Laravel, probably more. It's a big job no matter which approach you choose.

So ample time, planning, careful execution - and of course investment - are required to make a successful migration.

Here's a few of the challenges involved in upgrading to Yii 2:


Yii's Model classes changed a lot from Yii 1 to Yii 2. Particularly around search and DataProvider methods, in the definition of ActiveRecord relations and the model validation rules.

While this is an area of migration that can be partially automated (we have built our own tools to do so), it will still require some manual alterations of the Yii model code.

ActiveRecord queries

No more findByPk() and findAllByAttributes(), or horrible Yii 1 condition strings. Yii 2 introduced much cleaner query methods - but that means every Model/ActiveRecord/Query call will need to be re-written.

Views, forms & widgets

Massively painful. A large web application with 20+ controllers and 100+ views will have a lot of view code, possibly intertwined with Yii Bootstrap.

All the Yii 1 form & field declarations have to be updated, together with any GridView widgets and Yii helper code. This is by far the slowest and most repetitive aspect of the job, but can be speeded up with some crafty mass find and replace, and some PHP scripting to automate replacement.

Testing & zero downtime deployment

We've put careful thought and planning into how we'll test the new application and make sure it does everything the old version used to. Automated tests, regression testing, test plans and stages of factory and user acceptance tests will ensure that we cover every area of the application to confirm everything works as it should.

Furthermore, as for any mission-critical business operations app, we'll be deploying it onto AWS in a way that results in zero downtime.

Opportunities of migrating from Yii 1

It's not all doom and gloom though, it's a hugely rewarding, almost therapeutic process when rebuilding and refactoring an app.

It's an opportunity to find efficiencies and refactor areas that have built up duplication. It's also an opportunity to introduce modern web technology to enhance the application.

Screenshot of Yii 2 Framework code

StencilJS web components

For this particular app we decided to replace a bespoke PHP Yii widget with a StencilJS web component. Stencil is a JavaScript framework and toolset for building reusable and scalable design systems and user interfaces.

By introducing a new web component, we have been able to optimise a complex area of this Yii 1 application, and develop a more flexible and more easily maintained system.

Breaking out the monolith

A Yii 1 migration is also a good time to consider breaking off pieces of the application to become microservices, possibly using cost-effective and highly scalable serverless components such as AWS Lambda and DynamoDB.

Feature updates

Investing in a web application framework update is a bit like having to buy a replacement gearbox for your car. It's necessary, it's (potentially) expensive, but at the end of it, to outward appearances you'll have exactly what you had before.

So to provide better value for money and a more rewarding experience we like to incorporate feature updates during our Yii 1 migration process.

It's sensible to identify areas of the application that you want updating, so that during the migration we can make those changes as we go - a much more efficient process.

Then not only are you getting that lovely new gearbox (which you can't really see), you're also getting an extra gear.

Read more about the Yii Framework and the end of support for Yii 1: https://www.yiiframework.com/news/90/update-on-yii-1-1-support-and-end-of-life

Do you have any thoughts on this article? Get in touch: hello@sinovi.uk

About the author

James Galley

An AWS-certified developer, James architects and produces cloud-based web applications using Amazon Web Services. Recent projects include high-throughput event driven applications using Kinesis and DynamoDB, fully serverless web applications powered by AWS Lambda and high-performance static sites deployed to S3.

Profile image of James Galley
contact us

We're here to help

Talk to us today about updating from Yii 1 to Yii 2 or to other PHP frameworks like Laravel.

We're a software development and cloud consultancy, operating as an outsourced technology partner for businesses - building, hosting and maintaining functional web based applications in the AWS cloud with trusted web technologies.

Discuss your next project