If you encounter installation problems or other read/write limitations, try setting the following permissions for your Magento 2 installation.
1. Basic permissions setup
Set Magento Permissions:
We recommend permissions for Magento as follows:
- directories: 711
- php files: 600
- all other files: 644
This can be achieved with the following commands:
find . -type d -exec chmod 0711 {} +
find . -type f -exec chmod 0644 {} +
find . -type f -name “*.php” -exec chmod 600 {} +
chown -R owner:group . (including the last point dot, sets owner for all files under current Magento 2 installation) - Make sure you replace <owner>:<group> with your current user and the group that it's in. The most common ones are www-data:www-data, root:root, www-data:magento, etc however this can differ from server to server.
chmod u+x bin/magento (add the execute permissions for bin/magento)
2. Advanced permissions setup
When using your own server or a private hosting setup and you need to set ownership and permissions the following advanced procedure can be applied. On this type of server, you are not able to log in as, or switch to, the web server user. Usually you log in as one user and run the web server as a different user.
In order to enable the web server to write files and folders in the Magento file system, and at the same time to maintain ownership by the Magento file system owner, both users must be in the same group. This way both users can have access to the Magento files, including the files created also by the Magento Admin or other web-based application.
The following steps detail how to add your Magento file system owner/user in the web server's group on Apache servers. For other web servers or operating systems, you can use the equivalent commands.
1. Check your <your_username>
whoami
2. Find the web server's user
ps aux | grep apache
Usually, the apache user is www-data.
3. Find the web server user's group
groups www-data
Replace www-data with your apache user in case your web server user is different.
Usually, both user and the user's group are www-data.
4. Set the file system owner in the web server group (this needs to be done even if the user is root)
sudo usermod -a -G www-data <your_username>
This is how you add your user to the www-data group.
5. Make sure your user is a member of the web server group
groups <your_username>
The result should be that <your_username> from Step 1 is now part of multiple groups, including www-data, the web server group.
To complete this point, restart the web server:
- Ubuntu:
service apache2 restart
- CentOS:
service httpd restart
6. Set ownership and permissions
Use <web server group> found at Step 3
cd <to your Magento install directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chown -R <your_username>:<web server group> . (including the last dot, sets owner for all files under current M2 installation)
chmod u+x bin/magento (add the execute permissions for bin/magento)
Optionally, you can use the command in one line. Make sure you are in directory of your Magento2 installation, and we assume that the web server group is www-data:
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chown -R www-data:www-data . && chmod u+x bin/magento
In some case when the file system permissions are set improperly and can’t be changed by the Magento file system owner, you need to enter the commands as a user with root
privileges:
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; && sudo find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \; && sudo chown -R www-data:www-data . && sudo chmod u+x bin/magento
Note 1: Depending on how the server is configured, when copying files via FTP, the copied files may have the wrong permissions, or wrong group. In this case, run the above permission setup again after copying the new files.
Note 2: Make sure the user you are logged in with has all the necessary permissions and is assigned to the same group as Magento. A common problem is that Magento files have a different group than the files you just copied or installed, leading to various installation problems. For more details on this behavior you can check: Bitnami AWS - Installation issues with Magento 2 Theme or Extensions [Solved]
Comments
1 comment
well. with new pearl web installer gui, one needs to make app/code/WeltPixel folder writable because of the less generation in step-3.
# find var generated vendor pub/static pub/media app/etc app/code/WeltPixel app/code/WeSupply/ -type f -exec chmod g+w {} +
# find var generated vendor pub/static pub/media app/etc app/code/WeltPixel app/code/WeSupply/ -type d -exec chmod g+ws {} +
Please sign in to leave a comment.