Yii 1.1: "Why do I get a 403 error when trying to use Gii?"


After enabling the Gii module in your protected/config/main.php file and then try to use it with http://example.com/index.php?r=gii, you get an error:

Error 403
You are not allowed to access this page.

This is almost certainly caused by the IP filtering mechanism that Gii uses to protect your system from outsiders - by default it allows localhost only (both IPv4 and IPv6), and remote users (which apparently includes you) won't be allowed in.

To fix this, look in your main config file for the modules section for Gii, and add an ipFilters array that includes your own IP:

// protected/config/main.php
return array(
    'modules' => array(
        'gii' => array(
            'class'     => 'system.gii.GiiModule',
            'password'  => 'Enter Your Password Here',
            'ipFilters' => array('', ''),   // EDIT TO TASTE

The ipFilters property can include as many items as you like, and they can be straight IP addresses or wildcards such as "192.168.1.*".

IPv6 addresses are supported as well if the underlying platform supports it, and "::1" represents localhost (which may be required in some configurations).

Be careful not to open Gii to a too-wide audience lest it become a security risk.

Note: Yii 1.1.6 adds the default filter directly to the stock config file:

// If removed, Gii defaults to localhost only. Edit carefully to taste.

so this FAQ may not be so frequent much longer.

Total 3 comments

#15539 report it
pmaselkowski at 2013/11/20 03:15am
Re: Question on Gii

Thats right. Except ipFilters use strong password for proper security.

#13225 report it
Surface at 2013/05/16 04:56am
Thanks. It works fine.


#7862 report it
Toren at 2012/04/23 06:44pm
Question on Gii

Ok, so I am working on this behind a proxy server, SO the only way I can get GII to work is by allowing my public ip address, which is the same for everybody???

Leave a comment

Please to leave your comment.

Write new article
  • Written by: Steve Friedl
  • Category: FAQs
  • Yii Version: 1.1
  • Votes: +7 / -1
  • Viewed: 67,411 times
  • Created on: Dec 11, 2010
  • Last updated: Jan 30, 2011
  • Tags: Gii, config