13

I've install Yii2 framework using composer but get this error in my browser (on localhost):

Invalid Configuration – yii\base\InvalidConfigException

yii\web\Request::cookieValidationKey must be configured with a secret key.

How can I solve this problem?

4 Answers 4

21

There is this problem with basic app now https://github.com/yiisoft/yii2-app-basic/issues/69 where composer install doesn't generate this key.

You need to add this key manually.

  1. Go to /config/web.php.
  2. Edit the line 'cookieValidationKey' => '', to include random string (you can use anything like 'cookieValidationKey' => 'jfsbkjsbfdskjgfdskjbgfsdhjgfajds',
1
  • This solution is not working for me. Kindly see my question on it
    – Moeez
    Feb 13, 2020 at 9:31
2

You need to set cookieValidationKey in the config file to a random string. The config file is located under yii/your-projectfolder/config/main-local.php if you are using Yii 2.0 Advanced Template

2
  • i use basic template
    – Nikita
    Aug 8, 2016 at 8:17
  • Look for config/web.php
    – Jason
    Aug 8, 2016 at 8:36
2

enter image description here

You need to set cookieValidationKey value in project/config/web.php at line 12.

change at:

'cookieValidationKey' => '',

replace with:

'cookieValidationKey' => 'setyourkey',

enter image description here

That should address the issue.

0

Try this open Frontend/ config / main.php

'components' => [
    'request' => [
        'enableCookieValidation' => true,
        'enableCsrfValidation' => true,
        // 'cookieValidationKey' => 'xxxxxxx', // if u dont hv key just comment it 
    ],
],

if you have a web.php

'components' => [
        'request' => [
            'enableCookieValidation' => true,
            'cookieValidationKey' => 'your-validation-key',
        ],

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.