One of the common error for yii 2 framework when you activate the Gii tool “Gii Forbidden code 403 – You are not allow to access this page.”

gii forbidden code 403

This error came from the default yii doesn’t allow our IP to access this Gii page. To fix this issue, we must add our allowed IP into Gii module

Basic template.

Open the config/web.php and replace the default gii code with

if (!YII_ENV_TEST) {
 $config['bootstrap'][] = 'gii';
 $config['modules']['gii'] = [
  'class' => 'yiigiiModule',
  'allowedIPs' => ['127.0.0.1', '::1'],
 ];
}

If you are using the remote hosting, add your hosting IP inside the allowedIPs array.

Advanced template

Open the backend/config/main-local.php for backend or frontend/config/main-local.php for frontend, but I recommend you to put the code in back-end site.

Also change the code as below

if (!YII_ENV_TEST) {
 $config['bootstrap'][] = 'gii';
 $config['modules']['gii'] = [
  'class' => 'yiigiiModule',
  'allowedIPs' => ['127.0.0.1', '::1'],
 ];
}

Remember put your IP inside the allowedIps array.

Refresh the page and see your result.