Magento – File permissions changed after applying patch – 403 Forbidden Error!

magento-1.9patchespermissions

I was trying to install a patch through SSH and followed the directions to change folder permissions; it came up saying

operation not permitted

but now my site is down with a

403 – Forbidden Error

I am going through each folder manually trying to change the folder permissions back to 755 and the file permissions back to 644 but it's

  1. Taking forever
  2. More than possible that some will be missed.

Please help! How do I revert them all back?

Will typing this into my terminal help?

#!/bin/sh
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod 550 mage

I'm scared to touch SSH again. Can someone help me get it back?

Best Answer

While these permissions will get your site to work

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod 550 mage

They are certainly not recommended for you to use such wide open permissions. Before you start changing permissions you should understand what you are changing and why. The above example gives a lot of privileges to all your files and folders.

You should experiment with your permissions and to keep them as restrictive as possible. For example, most of your files can run with 440 (You can test)

Note from Magento suggestions here http://devdocs.magento.com/guides/m1x/install/installer-privileges_after.html

find . -type f -exec chmod 400 {} \;
find . -type d -exec chmod 500 {} \; 
find var/ -type f -exec chmod 600 {} \; 
find media/ -type f -exec chmod 600 {} \;
find var/ -type d -exec chmod 700 {} \; 
find media/ -type d -exec chmod 700 {} \;
chmod 700 includes
chmod 600 includes/config.php

You see that you regular files are not writable at all, only your media and var folders. If you are on a shared server you may have to change the second bit to something other than "0"

If the above example does not work then you can try:

find . -type f -exec chmod 440 {} \;
find . -type d -exec chmod 550 {} \; 
find var/ -type f -exec chmod 640 {} \; 
find media/ -type f -exec chmod 640 {} \;
find var/ -type d -exec chmod 750 {} \; 
find media/ -type d -exec chmod 750 {} \;
chmod 750 includes
chmod 640 includes/config.php

It is important that you don't leave your site wide open to the world!

Related Topic