I believe it's a un*x or apache question and it may not have a solution but I still hope to hear someone's opinions :)

When you installed a drupal on a machine with a non-root (or let say, non-www-data) account (ex, installed it under your personal account on a lab machine '~drake'), the whole files/directories are drake:ooxx. As documentation suggested, you create a folder 'files' under ~drake/public-html/ and give it access permissions open to all (chmod 777 files). Everything went fine except one day you gonna remove the drupal or move it to some other places(machines or folders). Then, the question appears:

You don't have permission to delete files under ~drake/public-html/files because all of them were created by www-data or some acount that web server runs as.

Does anyone have any good solution to this issue? The quickest way is call webadmin to help you remove those files/directories. and I am thinking is there some configuration way to tell apache when it is creating some files/directories under ~drake/public-html/files, make them 777 but 755 or 644.

Is it possible to do that in apache with just a .htaccess ?

Thx :)

Comments

GWL’s picture

When/if you need access to those forbidden directories, it's an easy fix ...

Just create a small php file in your drupal root directory containing this:

chmod("files", 0775);

Point your browser to that file, and you should now have necessary permissions to do whatever you need to do. It shouldn't affect Drupal's performance at all.

Note that once you see the directory structure, you'll probably need to repeat the process for all subdirectories under "files" as well:

chmod("files/pictures", 0775);
chmod("files/whatever", 0775);

Also, you can experiment with the permissions that work on your server ... 775 is what worked for me.

(Just be sure to delete that php file when you're done. That could be a dangerous thing to leave lying around.)

drakeguan’s picture

I think I can write up a php script to recursively chmod or even unlink(or remove) files~

good tips

although it's very dangerous :)

thx a lot

paddy_deburca’s picture

This is some code I found on http://php.net - just search for chmod and this snippet comes up

<?php
function chmod_R($path, $filemode) {
   if (!is_dir($path))
       return chmod($path, $filemode);

   $dh = opendir($path);
   while ($file = readdir($dh)) {
       if($file != '.' && $file != '..') {
           $fullpath = $path.'/'.$file;
           if(!is_dir($fullpath)) {
             if (!chmod($fullpath, $filemode))
                 return FALSE;
           } else {
             if (!chmod_R($fullpath, $filemode))
                 return FALSE;
           }
       }
   }
 
   closedir($dh);
  
   if(chmod($path, $filemode))
     return TRUE;
   else
     return FALSE;
}
?>

I have never run it - or even tested it - but this is a start.

Paddy.

http://deburca.org, and http://amadain.net

alexandreracine’s picture

If you have some kind of cpanel, you can use it to delete anything under your username path.

Alexandre Racine

www.gardienvirtuel.com Sécurité informatique, conformité, consultation, etc

www.salsamontreal.com La référence salsa à Montréal

drakeguan’s picture

thx a lot

I think I got what I need :)