Adrian Cornish
Adrian Cornish

Reputation: 23866

Yii 2.0 enabling remote access to gii

Simple question, trying to enable remote access to gii in yii 2 - docs say http://www.yiiframework.com/doc-2.0/guide-start-gii.html

Note: If you are accessing Gii from a machine other than localhost, the access will be denied by default for security purpose. You can configure Gii to add the allowed IP addresses as follows,

'gii' => [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'] // adjust this to your needs
],

Thing is, it doesn't say where to add this - guesing config/web.php

But under what section?

Upvotes: 5

Views: 4410

Answers (1)

Mihai P.
Mihai P.

Reputation: 9357

2 places you need to add this.

Usually it is done like this in your main-local.php

if (!YII_ENV_TEST) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];   
}

So you need to add gii in the bootstrap section of the config and in the modules section. This will turn basically append them to the array from your config/main.php return [ 'id' => 'app-backend', 'basePath' => dirname(DIR), 'controllerNamespace' => 'backend\controllers', 'bootstrap' => ['log'], 'modules' => [ ], ],

On the link you gave, take a look above. You should do:

if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'] // adjust this to your needs
];
}

Upvotes: 5

Related Questions