Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Gii Forbidden code 403 You are not allowed to access this page

Tags:

php

yii2

gii

I have a server machine and I am trying to allow my PC ip address to use gii.

My PC ip address is 192.168.1.101

The server machine ip is 192.168.1.102.

I used composer to install the gii module.

This is how my composer.json settings look like:

"require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "yiisoft/yii2-gii": "*"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*"
    },

I have used php init and composer update and php yii migrate.

I am also logged in in the frontend.

This is the main.php file content:

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['gii'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
    ],
    'params' => $params,
    'modules' => [
        'gii' => [
            'class' => 'yii\gii\Module',
            'allowedIPs' => ['127.0.0.1', '::1', '192.168.1.101'],
            'password' => '123456'
        ],
    ],
];
like image 613
Ionut Flavius Pogacian Avatar asked Oct 11 '14 14:10

Ionut Flavius Pogacian


3 Answers

I had a similar issue and tried all different ipFilter changes. In the end I needed to add this to main-local.php. Which was strange because I had an advanced application, and the settings were for a 'yii2 basic' setup.
http://www.yiiframework.com/doc-2.0/guide-start-gii.html

if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';}

I should also point out, I did add this to main.php

    'modules' => [
    'gii' => [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.1.*', 'XXX.XXX.XXX.XXX'] // adjust this to your needs
    ],
],
like image 197
johnsnails Avatar answered Oct 21 '22 13:10

johnsnails


After init in dev mode I had to change my \backend\config\main-local.php and add the 'allowedIPs'.

Allows ALL IPs, so only recommended for internal dev use! Adjust to your needs.

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['*'],
];
like image 19
mfgmicha Avatar answered Oct 21 '22 15:10

mfgmicha


Change your /common/config/main-local.php as follows:

    return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=YourDatbase',
            'username' => 'YourDBUserName',
            'password' => 'YourDBPassword',
            'charset' => 'utf8',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
    ],
    // Add this to get debug and gii to work
    'modules' => [
        'gii' => [
            'class' => 'yii\gii\Module',
             // permits any and all IPs
             // you should probably restrict this
            'allowedIPs' => ['*']
        ],
        'debug' => [
            'class' => 'yii\debug\Module',
             // permits any and all IPs
             // you should probably restrict this
            'allowedIPs' => ['*']
        ]
    ]
];
like image 9
user2161402 Avatar answered Oct 21 '22 15:10

user2161402