Well, some times you find yourself in a situation where you have code uploaded to your server but permissions are not correct, definitely its hectic to change the permissions of all files one by one, you can use cpanel but still that doesn’t allow you to change permissions recursively (in the inner directories or files), you can do it via ftp software but that is too slow, it might take more that 30 minutes to assign correct permissions to a magento site.

You will be surprised that we still have a way to assign correct permissions to all the directories recursively in few seconds, isn’t it amazing?

Lets do it πŸ˜‰

1. create a php file “perm.php” and put following code in it

<?php

//a recursive function to iterate through all inner directories and change permissions
function chmod_r($path) {
    $dir = new DirectoryIterator($path);
    foreach ($dir as $item) {
        chmod($item->getPathname(), 0755);
        if ($item->isDir() && !$item->isDot()) {
            chmod_r($item->getPathname());
        }
    }
}

//you can go to one directory above by un-commenting following line
//chdir("..");

$path = getcwd(); 
chmod_r($path);

echo "Permissions applied to all files and directories";

2. upload perm.php to the root folder of your code
3. change permissions of perm.php to 0755
4. run perm.php in your browser like http://www.example.com/perm.php

Enjoy πŸ™‚

Advertisements