没有不值得去解决的问题,也没有不值得去学习的技术!

Error After Running the init Command in Yii2: yii\web\Request::cookieValidationKey Must Be Configured With a Secret Key

在 Yii2 中执行 init 命令后,报错:yii\web\Request::cookieValidationKey must be configured with a secret key.

1. After running the init command in Yii2, an error occurred: yii\web\Request::cookieValidationKey must be configured with a secret key. See Figure 1.

After running the init command in Yii2, an error occurred: yii\web\Request::cookieValidationKey must be configured with a secret key.
Figure 1

2. I finally decided to improve the set of files under the environments directory, because this is a copied new application. During the “generate cookie validation key in” step, I confirmed that the file corresponding to the domain https://tougao.apply.local was missing: generate cookie validation key in papersubmission/config/main-local.php. See Figure 2.

I finally decided to improve the set of files under the environments directory, because this is a copied new application. During the "generate cookie validation key in" step, I confirmed that the file corresponding to the domain https://tougao.apply.local was missing: generate cookie validation key in papersubmission/config/main-local.php
Figure 2
Plaintext

PS C:\wwwroot\apply-server\src> ./init
Yii Application Initialization Tool v1.0

Which environment do you want the application to be initialized in?

  [0] Development
  [1] Production

  Your choice [0-1, or "q" to quit] 0

  Initialize the application under 'Development' environment? [yes|no] yes

  Start initialization ...

      exist api/config/main-local.php
            ...overwrite? [Yes|No|All|Quit] All
  overwrite api/config/main-local.php
  unchanged api/config/params-local.php
  unchanged backend/config/codeception-local.php
  overwrite backend/config/main-local.php
  unchanged backend/config/params-local.php
  unchanged backend/config/test-local.php
  unchanged backend/web/index-test.php
  unchanged backend/web/index.php
  unchanged backend/web/robots.txt
  overwrite common/config/codeception-local.php
  overwrite common/config/main-local.php
  overwrite common/config/params-local.php
  unchanged common/config/test-local.php
  unchanged console/config/main-local.php
  unchanged console/config/params-local.php
  unchanged console/config/test-local.php
  unchanged frontend/config/codeception-local.php
  overwrite frontend/config/main-local.php
  unchanged frontend/config/params-local.php
  unchanged frontend/config/test-local.php
  unchanged frontend/web/index-test.php
  unchanged frontend/web/index.php
  unchanged frontend/web/robots.txt
  overwrite management/config/main-local.php
  unchanged management/config/params-local.php
  unchanged papersubmission/config/main-local.php
  unchanged papersubmission/config/params-local.php
  unchanged yii
  unchanged yii_test
  unchanged yii_test.bat
   generate cookie validation key in backend/config/main-local.php
   generate cookie validation key in common/config/codeception-local.php
   generate cookie validation key in frontend/config/main-local.php
   generate cookie validation key in management/config/main-local.php
   generate cookie validation key in api/config/main-local.php
      chmod 0777 backend/runtime
      chmod 0777 backend/web/assets
      chmod 0777 console/runtime
      chmod 0777 frontend/runtime
      chmod 0777 frontend/web/assets
      chmod 0777 api/runtime
      chmod 0777 api/web/assets
      chmod 0777 management/runtime
      chmod 0777 management/web/assets
      chmod 0755 yii
      chmod 0755 yii_test

  ... initialization completed.

3. Copy /environments/dev/frontend to /environments/dev/papersubmission, copy /environments/prod/frontend to /environments/prod/papersubmission, and then edit /environments/index.php to add the configuration items related to papersubmission. See Figure 3.

Copy /environments/dev/frontend to /environments/dev/papersubmission, copy /environments/prod/frontend to /environments/prod/papersubmission, and then edit /environments/index.php to add the configuration items related to papersubmission
Figure 3

4. After running the init command again in Yii2, the error no longer occurs.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系