Skip to content
Home » News » How to Set Up Magento 2 Correct Permissions: Basic Setup

How to Set Up Magento 2 Correct Permissions: Basic Setup

Setting correct permissions is essential for a smooth Magento 2 installation and operation. Improper file and incorrect folder permissions can lead to installation issues, errors, such as the Permission denied error message discussed in one of the previous articles, or problems with reading and writing files. This guide provides simple steps for configuring permissions in Magento 2 for a basic setup.

Magento 2 Basic Permissions Setup

For most installations, you can use these basic permissions:

  • Directories: 711
  • PHP Files: 600
  • Other Files: 644

Steps to Set Basic Magento 2 Correct Permissions

  1. Open your terminal and navigate to your Magento installation directory.

Run the following commands to apply the recommended permissions:

find . -type d -exec chmod 711 {} +  
find . -type f -exec chmod 644 {} +  
find . -type f -name "*.php" -exec chmod 600 {} +  
  1. Set ownership for all files:
chown -R <owner>:<group> .  
  1. Replace <owner> and <group> with your server’s user and group (e.g., www-data:www-data or root:root).

4. Add execute permissions to the bin/magento file:

chmod u+x bin/magento  

Special Notes

  1. Temporary Directories:

Ensure /var, /pub/media, and /pub/static have public access if required:

find ./var ./pub/media ./pub/static -type d -exec chmod 777 {} \;  
  1. Avoid Setting 777 Permissions on Sensitive Directories:
    Never set 777 permissions for /app/etc or other sensitive directories, as this could expose your store to security risks.
  2. File Copying Issues:
    When copying files via FTP, permissions may reset. Reapply the above steps after uploading new files.
  3. Root Privileges:
    If you encounter permission errors that cannot be resolved as a regular user, use sudo to run the commands with root privileges. For example:
sudo php bin/magento ...

Conclusion

Configuring permissions in Magento 2 is important for a secure and functional store. Use these steps to set up Magento 2 correct permissions and always double-check sensitive directories to avoid potential security risks.

Author

Leave a Reply

Your email address will not be published. Required fields are marked *