1、之前已安装 Composer,为确保使用最新版本。可以通过运行 composer self-update 来更新 Composer 至版本 2.0.12,如图1

PS E:\> composer self-update
Updating to version 2.0.12 (stable channel).
Downloading (100%)
Use composer self-update --rollback to return to version 1.10.6
2、通过运行 composer update 来更新 Yii 2 至最新版本,已将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1,如图2

PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer update
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 68 updates, 1 removal
...
- Upgrading yiisoft/yii2 (2.0.35 => 2.0.41.1)
- Upgrading yiisoft/yii2-composer (2.0.9 => 2.0.10)
- Upgrading yiisoft/yii2-debug (2.1.13 => 2.1.16)
- Upgrading yiisoft/yii2-faker (2.0.4 => 2.0.5)
- Upgrading yiisoft/yii2-httpclient (2.0.12 => 2.0.13)
...
Package flow/jsonpath is abandoned, you should avoid using it. Use softcreatr/jsonpath instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Seems you have upgraded Yii Framework from version 2.0.35 to 2.0.41.1.
Please check the upgrade notes for possible incompatible changes
and adjust your application code accordingly.3、先解决与 “fxp/composer-asset-plugin” 相关的提示信息。如图3

The "fxp/composer-asset-plugin" plugin (installed globally) was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
4、参考网址:https://www.yiiframework.com/doc/guide/2.0/zh-cn/structure-assets 。注意: 从 2.0.13 开始,基本和高级应用程序模板都默认配置使用 asset-packagist。决定全局删除 “fxp/composer-asset-plugin”。如图4

PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer global remove fxp/composer-asset-plugin
Changed current directory to C:/Users/Administrator/AppData/Roaming/Composer
The "fxp/composer-asset-plugin" plugin was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
fxp/composer-asset-plugin is not required in your composer.json and has not been removed
./composer.json has been updated
The "fxp/composer-asset-plugin" plugin was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
Running composer update fxp/composer-asset-plugin
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 0 updates, 1 removal
- Removing fxp/composer-asset-plugin (v1.4.4)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 0 updates, 1 removal
- Removing fxp/composer-asset-plugin (v1.4.4)
Generating autoload files
PS E:\wwwroot\github-shuijingwan-yii2-app-advanced>
5、再次运行 composer update 来更新 Yii 2 至最新版本,未再报错与 “fxp/composer-asset-plugin” 相关的提示信息。但是,仍然存在其他的提示信息。如图5

PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer update
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 0 updates, 0 removals
Package flow/jsonpath is abandoned, you should avoid using it. Use softcreatr/jsonpath instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
47 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
6、包 flow/jsonpath 被放弃了,您应该避免使用它。请改用 softcreatr/jsonpath。决定卸载 flow/jsonpath ,安装 softcreatr/jsonpath。如图6

PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer remove flow/jsonpath
./composer.json has been updated
Running composer update flow/jsonpath
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 0 updates, 1 removal
- Removing flow/jsonpath (0.5.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 0 updates, 1 removal
- Removing flow/jsonpath (0.5.0)
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
47 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer require --prefer-dist softcreatr/jsonpath
Using version ^0.7.3 for softcreatr/jsonpath
./composer.json has been updated
Running composer update softcreatr/jsonpath
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
- Locking softcreatr/jsonpath (0.7.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Downloading softcreatr/jsonpath (0.7.3)
- Installing softcreatr/jsonpath (0.7.3): Extracting archive
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
48 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PS E:\wwwroot\github-shuijingwan-yii2-app-advanced>
7、软件包 phpunit/php-token-stream 被放弃了,您应该避免使用它。没有建议更换。使用 依赖性检测 depends 命令可以查出已安装在你项目中的某个包,是否正在被其它的包所依赖,并列出他们。得出结论:phpunit/php-code-coverage 依赖于 phpunit/php-token-stream,codeception/phpunit-wrapper、phpunit/phpunit 依赖于 phpunit/php-code-coverage,codeception/codeception、codeception/lib-asserts、codeception/verify 依赖于 codeception/phpunit-wrapper,层层依赖。决定保持此提示,暂时无解决方案。如图7

PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends phpunit/php-token-stream
phpunit/php-code-coverage 7.0.14 requires phpunit/php-token-stream (^3.1.1 || ^4.0)
PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends phpunit/php-code-coverage
codeception/phpunit-wrapper 8.1.4 requires phpunit/php-code-coverage (^7.0)
phpunit/phpunit 8.5.15 requires phpunit/php-code-coverage (^7.0.12)
PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends codeception/phpunit-wrapper
codeception/codeception 4.1.20 requires codeception/phpunit-wrapper (>6.0.15 <6.1.0 | ^6.6.1 | ^7.7.1 | ^8.1.1 | ^9.0)
codeception/lib-asserts 1.13.2 requires codeception/phpunit-wrapper (>6.0.15 <6.1.0 | ^6.6.1 | ^7.7.1 | ^8.0.3 | ^9.0)
codeception/verify 1.1.0 requires codeception/phpunit-wrapper (>6.0.15 <6.1.0 | ^6.6.1 | ^7.7.1 | ^8.0.4)
PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends codeception/codeception
shuijingwan/yii2-app-advanced dev-master requires (for development) codeception/codeception (^4.0)
codeception/lib-innerbrowser 1.4.2 requires codeception/codeception (*@dev)
codeception/module-asserts 1.3.1 requires codeception/codeception (*@dev)
codeception/module-filesystem 1.0.3 requires codeception/codeception (^4.0)
codeception/module-yii2 1.1.2 requires codeception/codeception (^4.0)
PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends phpunit/phpunit
codeception/phpunit-wrapper 8.1.4 requires phpunit/phpunit (^8.0)
codeception/stub 3.7.0 requires phpunit/phpunit (^8.4 | ^9.0)
codeception/verify 1.1.0 requires phpunit/phpunit (> 6.0)
8、在线查看 Yii Framework 2.0 升级说明:https://github.com/yiisoft/yii2/blob/2.0.41.1/framework/UPGRADE.md ,了解可能不兼容的更改,比如,扩展了某些类,而这些类的属性与方法在新版本中有所调整。
PHP / Laravel / Yii2 老项目维护与长期技术支持
如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。
适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护
可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查
如需咨询,请联系我,并注明:PHP 维护咨询。
联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

评论
2 条对“基于 Composer 更新 Yii 2 至最新版本,将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1”的回复
[…] 上一篇 基于 Composer 更新 Yii 2 至最新版本,将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1 […]
[…] Reference URL: Updating Yii 2 to the latest version via Composer, upgrading Yii Framework from version 2.0.35 to 2.…. ./yii produces no output. See Figure […]