Gii - Testing Model Generator

I just installed Yii and while following this tutorial:

I got to the part about trying the Model Generator. After hitting generate it gave me the following error:

Generating code using template "/var/www/html/–/framework/gii/generators/model/templates/default"…

generating models/User.php

     [b]  Unable to write the file '/var/www/html/--/testdrive/protected/models/User.php'.[/b]


I assume it’s a CHMOD issue, but I want to make sure I am following the proper protocol before CHMOD’ing random directories.

Just check if your web user has a write permission to the protected/models directory for creating models… and to the protected/controllers and protected/views for creating CRUD…

A good idea is to remove those permissions when you finish to use Gii…

Thank you. Can you let me know exactly which permission this should be? Is it 0666?

No, 666 is read and write permission to everybody.

0644 or chmod u+w gives the user who belong to the file/dir (should be your web user) write permissions.

On the following page you can check the different numeric permissions and their meanings

Since the webserver needs permission to write to the Yii "protected" folder that is most probably owned by you (<user> see: ls -al). Why not do this instead of chmod:

Add your linux <user> to the webserver group.

On default LAMP, webserver group is "www-data". On Zend Server CE the webserver goup is "zend".

On terminal do this:

  1. groups <user>

Will show you the groups you are in. Check for www-data || zend.

sudo usermod -a -G www-data <user> (for standard Apache install)


sudo usermod -a -G zend <user> (for Zend Server CE)

so here you are assigning yourself (<user>) to the webserver group.

  1. you are good to go. No more write problem.


you can change to 775 for now when you done you can change back to default

For Mac OS X users::

Locate the folder containing the yii resources(maybe inside htdocs, if you’re using xampp)

Right-Click, click on ‘Get Info’

Click the lock item at the bottom(you may need to scroll down)

Enter your admin password

Change Permission for Admin and Everyone to ‘Read and Write’ and Click the Apply Icon