I have a Yii2 project and I have been using this yii2 project since 2015. The installed version was 2.0.6. Today Yii2 releases a new version which is Yii 2.0.37. I will share with you how to upgrade Yii2 via composer.
Install composer
First, you need a composer in your computer. If you don’t have the composer in your computer yet, you can install the composer from this link.
Update Yii2 by composer
Once the composer is ready, you can run this command in the terminal for upgrade Yii2 to the latest version.
composer require "yiisoft/yii2:*" --update-with-dependencies
If you just want to upgrade Yii2 to the version you want, you can run this command in the terminal. Let’s say, I want to upgrade Yii2 to 2.0.10. I will run the command below.
composer require "yiisoft/yii2:~2.0.10" --update-with-dependencies
You can change 2.0.10 to any versions you want in the command above.
Your package name is invalid error
In my case, when I run `composer -V` in the terminal for checking the composer version, I have this error.
Deprecation warning: Your package name xyz is invalid, it should have a vendor name, a forward slash, and
a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$". Make sure you fix this as Composer 2.0 will error.
Composer version 1.10.10 2020-08-03 11:35:19
This error comes from composer.json in name key.
I normally commit my projects in github or other source control. In my case, my vendor name is glabtech which is my username for the github. So my package name should be glabtech/xyz.
Once I change the package name to glabtech/xyz in composer.json and run the `composer -V`in the terminal. The error is gone. Next, I will upgrade Yii2 to latest version with composer command.
Update all dependency packages for Yii2
First, you check what Yii2 template do you use. I use Yii2-app-advanced template. So I will look at composer.json for Yii2-app-advanced template.
Then I update the packages in require, require-dev, config and repositories sections by copying the packages from yii2 composer.json to my yii2 composer.json. In my case, I don’t have the repositories section, so I copy the repositories section from yii2 composer.json to my yii2 composer.json.
After that, you will run the command below for updating all packages in composer.json.
composer update
That’s it for today.