yii2-gii
yii2-gii copied to clipboard
Gii Generating Incorrect File Permissions - 666 and 777
I am not sure if it is just me, or if it is a bug.
Gii is generating files with 666 permission and directories with 777. I noticed in the yii2-gii/Model.php file that these are the defaults Gii has stored.
When I used composer to install Yii2, it has all the directories as 755 and files as 644, which is correct. I ran some stuff with Gii, and committed the changes to git, and it went nuts about changing the permissions to 666 and 777.
That didn't look right, so I inspected the files/folders of my project. I actually made a bash script to make ls -al show the numerical permissions with my own cll command, to make this easier. I noticed that things I generated with Gii, have the incorrect permissions (666 and 777).
Shouldn't Gii have these set as 644 and 755 by default?
Gii -> Module.php -> newFileMode
Gii -> Module.php -> newDirMode
Is there something wrong on my end, or should we update Gii's Module.php to have the correct permissions?
Additional info
| Q | A |
|---|---|
| Yii vesion | 2.0.9 |
| PHP version | 5.5.34 |
| Operating system | OSX El Capitan 10.11.5 |
I am also using XAMPP 5.6.21-0 and Apache/2.4.18 (Unix)
Shouldn't Gii have these set as 644 and 755 by default?
probably yes. They normally should also depend on the umask, need to check why they do not.
Shouldn't Gii have these set as 644 and 755 by default?
This will cause problems when you're running webserver on different system user than you - you will not be able to edit generated files.
OMG I need to go to bed. So, originally, Gii did generate these files... However, they were copied from one directory to another. I had another app I already made previously, and copied them over instead of repeating myself.
I am not sure if it was due to being zipped, moved, unzipped.. then copied.. or what. Seems that either from zipping the other app, or copying the files from it, the files lost their permissions.
Is this normal behavior on a Mac? I had a zip of my other app. I unzipped it and picked out some files I needed. Do you guys also have to manually chmod the files you copied? or do I need to fix something lol
You can close this 👍 Sorry guys!
zip does not keep file permissions, tar does.
This actually seems to be a real issue after all. I am not sure if it is setup related or Gii related.
I am on a Macbook Pro El Capitan 10.11.5 using XAMPP, and running Gii from backend in Chrome.
After creating a simple controller in Gii, I get this:
Wades-MBP:yii2-marketing-system work$ cd frontend/views
Wades-MBP:views work$ cll
0200 total 0
0755 drwxr-xr-x 6 work admin 204 Jul 11 17:45 .
0755 drwxr-xr-x 11 work admin 374 Jul 10 01:19 ..
0777 drwxrwxrwx 3 work admin 102 Jul 11 17:45 affiliate <-- gii created directory!
0755 drwxr-xr-x 11 work admin 374 Jul 10 01:19 layouts
0755 drwxr-xr-x 11 work admin 374 Jul 10 01:19 site
0755 drwxr-xr-x 10 work admin 340 Jul 10 01:19 user
Wades-MBP:views work$ cd affiliate
Wades-MBP:affiliate work$ cll
0200 total 8
0777 drwxrwxrwx 3 work admin 102 Jul 11 17:45 .
0755 drwxr-xr-x 6 work admin 204 Jul 11 17:45 ..
0666 -rw-rw-rw- 1 work admin 175 Jul 11 17:45 index.php <-- gii created file!
Wades-MBP:affiliate work$
Note: cll is a custom command I made to show the permissions nicely.
One thing I want to add, is I have changed my user/group in httpd. My group is "admin" instead of a user group, so could that throw off umask? I changed it because php wasn't able to create any files at all, with default xampp, due to the apache user being "daemon".
<IfModule unixd_module>
#User daemon
#Group daemon
User work
Group admin
</IfModule>
I know, I shouldn't be an admin user, but I am sure many of us do :)
I am open to switching from xampp and trying something else. It's the first one I used after converting to a Mac. MAMP doesn't seem as "free" as WAMP :(. Let me know what you use, and I will try it. might reduce future errors, so we are on the same page.
A working solution, is to set the permissions manually in the config (main-local.php):
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'newFileMode' => 0644,
'newDirMode' => 0755,
];
This seems to work just fine. However, the real issue is why the extra hoops when most probably don't have to manually set these, and umask works fine for them?
This issue is still popping up on me :(
Anyone else on a stock XAMPP and Mac getting this?