Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adjust webserver group name to match your system! (_www is the default Apache httpd usergroup on OS X)
#!/bin/bash
[ ! -d app ] && echo "Not in Magento 2 root directory" >&2 && exit 1
echo "Settting group ownership to _www"
chgrp -R _www .
echo "Setting directory base permissions to 0750"
find . -type d -exec chmod 0750 {} \;
echo "Setting file base permissions to 0640"
find . -type f -exec chmod 0640 {} \;
echo "Setting group write and sgid bit permissions for writable directories"
find var pub/media pub/static -type d -exec chmod g+ws {} \;
echo "Setting permissions for files in writable directories "
find var pub/media pub/static -type f -not -name .htaccess -exec chmod g+w {} \;
[ -e app/etc ] && echo "Making app/etc writable for installation"
[ -e app/etc ] && chmod g+w app/etc
echo "Making vendor/bin scripts executable"
find -L vendor/bin -type f -exec chmod u+x {} \;
echo "Making bin/magento executable"
chmod u+x bin/magento
@kojiromike

This comment has been minimized.

Copy link

commented Jan 26, 2016

I suggest chmod -R u+rwX,g+rX,o-rwx . instead of the first two find commands.

@Vinai

This comment has been minimized.

Copy link
Owner Author

commented Jan 26, 2016

Thanks for your suggestion, but if Magento ships a file with the executable bit set by accident, then +X would preserve it (which happened in the past).
I prefer to start with fixed base permissions like 0640 because of that.

@vkerkhoff

This comment has been minimized.

Copy link

commented Jan 27, 2016

The command chmod is missing in the exec option on line 16.

@devamitbera

This comment has been minimized.

Copy link

commented Jan 28, 2016

Hey Vinai.

Thanks for Share

@Vinai

This comment has been minimized.

Copy link
Owner Author

commented Jan 29, 2016

Thanks @vkerkhoff! I wonder how that happened. It is present in the file in my ~/bin dir, must have messed it up after copying maybe. Sorry.

@wjarka

This comment has been minimized.

Copy link

commented Feb 1, 2016

What about using xargs instead of -exec?

find . -type d -print0 | xargs -0 chmod 0750

Makes a huge difference performance-wise (on one of the test machines it made a difference between 4 minutes and 12 seconds) :-).

@Vinai

This comment has been minimized.

Copy link
Owner Author

commented Feb 17, 2016

@wjarka It does make a big difference performance wise, but I'm always afraid I'll run into an argument length limitation. if case there are too many files. On OS X the limit for the command argument length is 256KB (see echo $(getconf ARG_MAX) / 1024 | bc). Not sure how many file names fit into that, if the command itself is included in that limit, or how that value is different on other operating systems.

@digimix

This comment has been minimized.

Copy link

commented Mar 31, 2016

find . -type d -print0 | xargs -0 chmod 0750 works for me on Ubuntu 14.04 PHP7.0 LEMP thanks @wjarka

@devamitbera

This comment has been minimized.

Copy link

commented Jun 4, 2016

Hi Vinai

For share hosting it difficult to change user.Then what will be good idea. For a case, i have change file permission from Magento\Framework\Exception\FileSystemException\DriverInterface i have change WRITEABLE_DIRECTORY_MODE = 0770; to WRITEABLE_DIRECTORY_MODE = 0775; and WRITEABLE_FILE_MODE = 0660 to WRITEABLE_FILE_MODE = 0664.It is working for me.

Are u thought that is identical process for share hosting ?please put your view

Thanks

Amit Bera

@senthilengg

This comment has been minimized.

Copy link

commented Aug 7, 2016

@Vinai

Looks like its deviated from the recommendation here in the below link

http://devdocs.magento.com/guides/v2.0/config-guide/prod/prod_file-sys-perms.html#mage-owner-two-devel

As per the above link the file permission should have 775. Can you please clarify.

@vaimo-wilko

This comment has been minimized.

Copy link

commented Jul 13, 2017

When using the xargs approach, you can add the -n parameter to limit how many arguments are given to each invocation of the utility that xargs should run. e.g. find . -type d -print0 | xargs -0 -n10 chmod 0750 would run chmod with 10 directories at a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.