How can you reset Magento Files and Directory permissions?

Change the directory to the directory where Magento is installed and execute the following commands.

1.

find. -type d -exec chmod 755
2.

chmod+x magento

To reset Magento files and directory permissions, you can follow these steps:

  1. SSH Access: Ensure you have SSH access to your Magento server.
  2. Navigate to Magento root directory: Use the terminal to navigate to the root directory of your Magento installation.
  3. Reset Permissions: Run the following commands to reset file and directory permissions:
    bash
    find . -type f -exec chmod 644 {} \; # Set all file permissions to 644
    find . -type d -exec chmod 755 {} \; # Set all directory permissions to 755
    find ./var -type d -exec chmod 777 {} \; # Set var directory permission to 777
    find ./pub/media -type d -exec chmod 777 {} \; # Set media directory permission to 777
    find ./pub/static -type d -exec chmod 777 {} \; # Set static directory permission to 777
    chmod 777 ./app/etc # Set app/etc directory permission to 777
    chmod 644 ./app/etc/*.xml # Set app/etc/*.xml permissions to 644
  4. Owner and Group: Set appropriate ownership and group for Magento files. This typically involves setting the owner to the web server user (e.g., www-data for Apache) and the group to the web server group:
    bash
    chown -R <your_web_server_user>:<your_web_server_group> .
  5. Re-index and clear cache: After resetting permissions, it’s advisable to re-index and clear the cache to ensure Magento functions properly:
    bash
    php bin/magento indexer:reindex
    php bin/magento cache:clean
    php bin/magento cache:flush
  6. Check for Errors: After resetting permissions, check your website thoroughly for any errors. If you encounter any issues, review the permissions and ownership settings to ensure they are correctly configured.
  7. Automation (Optional): You can automate permission fixing with cron jobs or deployment scripts, ensuring permissions are consistently maintained.

By following these steps, you can reset Magento file and directory permissions to ensure proper functioning of your Magento store.