gii needs write permissions

I’m going through the Definitive Guide to Yii 2.0, and I just got to the Gii page ( Gii is cool!

However, I wanted to suggest an addition to the guide: a brief discussion of users and permissions. Because it turns out that, at least with my Apache settings in OS X 10.10.3, Apache operates as a user named “_www”, which means that by default it doesn’t have permission to do anything useful.

For example, I ran into problems trying to use the Model Generator, in the "Generating an Active Record Class" section. I followed the instructions there, but when I clicked Generate to overwrite the Country.php file, Gii told me this:

There was something wrong when generating the code. Please check the following messages.

Generating code using template "/Users/jhartman/Sites/basic/vendor/yiisoft/yii2-gii/generators/model/default"…

generating models/Country.php

Unable to write the file ‘/Users/jhartman/Sites/basic/models/Country.php’.


(It would also be really useful if Gii could add a note to the error message suggesting that the Apache user might be the problem.)

When I deleted the existing Country.php file (created during a previous page of the tutorial), I got a similar error message.

After some trial and error, I figured out that Gii is operating as use “_www”, and thus that I need to change the file and the directory permissions to 777 (instead of 755 or 644) to allow Gii to write to the directory. It looks like there are ways to change the Apache default user, but even so, it seems like Apache’s default behavior (at least in OS X) prevents Gii from working. So I thought it was worth mentioning here.

  • operating system: OS X 10.10.3

  • Web server: Apache

  • browser type: Chrome

  • Yii version: 2.0

A solution is giving models, controlles and views directory 777 for gii and then revoke. But I wonder why nobody replied this.