Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is the root directory where all files are kept (directly from accessing from FTP) always "www" or "public_html" depending on what OS? Or is it possible to rename this folder? And if so, what would be unique about this folder to be able to identify it? i.e. currently I just wrote this;

my $root;
my $ftp = Net::FTP->new($DB_ftpserver, Debug => 0) 
                              or die "Cannot connect to some.host.name: $@";
$ftp->login($DB_ftpuser, $DB_ftppass) or die "Cannot login ", $ftp->message;
my @list = $ftp->dir;

if( scalar @list != 0 ) {
  foreach( @list ){
     if( $_ =~ m/www$/g ){
       $root = "www";
       last;
     }elsif( $_ =~ m/public_html$/g ){
       $root = "public_html";
       last;
     }
   }
 }

but would not work if it has a different name.

Any help much appreciated.

share|improve this question

migrated from stackoverflow.com Feb 6 '10 at 23:45

This question came from our site for professional and enthusiast programmers.

    
My Document Root is always ~/domainname/ for each website. You can configure this how you like. –  Rich Bradshaw Feb 7 '10 at 10:25
add comment

6 Answers 6

It all depends on the default configuration of the server. You can configure to another location as well.

On Windows it can be:

C:\xampp\htdocs\

or

C:\vhost\public\www\

or somewhere different.

Belongs on superuser ain't it?

share|improve this answer
add comment

The name is configurable in Apache (DocumentRoot - default, according to the 2.2.x documentation, is /usr/local/apache/htdocs). My machine at the office uses neither of the options you mention (offhand, I think it uses htdocs, but its a while since I last fiddled with it).

OTOH, since you mention FTP, perhaps you are thinking of something else; the base directory is still configurable, though.

share|improve this answer
add comment

Ok, I have changed slightly, but to the second part of my question, is there anyway of identifying which folder is main?

    my $root;
    my $ftp = Net::FTP->new($DB_ftpserver, Debug => 0) or die "Cannot connect to some.host.name: $@";
    $ftp->login($DB_ftpuser, $DB_ftppass) or die "Cannot login ", $ftp->message;
    my @list = $ftp->dir;
    if( scalar @list != 0 ) {
        foreach( @list ){
            if( $_ =~ m/(?:(?:www)|(?:public_html)|(?:htdocs))$/g ){
                $root = $1;
                last;
            }
        }
    }

    if( $root eq "" ) {
        print "error: could not identify root directory.<br />\n";
        die;
    }
share|improve this answer
    
It's better that you edit your own question instead of answering it with another question –  Yoni Feb 6 '10 at 8:13
    
Yeah so 1/2 of everyone says. The other 1/2 say post it new so they can read the code... The actual layout for posting on this site isn't great but you get good response and answers! –  Phil Jackson Feb 6 '10 at 8:19
add comment

I don´t know if that is configurable, I think it depends on what webserver you´re using, so check your webserver manual. Good luck!

share|improve this answer
add comment

Apache provides an environment variable named 'DOCUMENT_ROOT' for this very task (i.e. identifying what the docroot actually is from within a script).

share|improve this answer
add comment

I'll speak in terms of Apache httpd, since it's a very popular webserver.

The root directory where all files are kept, is generically named DocumentRoot. Please bear in mind that files are kept in DocumentRoot for being served by the web server, not for being shown to you when you log in via FTP. FTP is a totally different protocol that is not related to web sites and in this context it is just a way to allow you, the user, modify/update files on a remote server.

The www / public_html directory that you talk about in your question is probably not DocumentRoot. This is additional functionality of Apache, the mod_userdir module. Please consult its documentation.

As said in the docs, there's an UserDir setting in Apache's configuration file which lets you customize the name of these user directories, from where the web server will serve the sites that belong to different users.

Since there's no restriction on UserDir, you can have anything there, even foobar. You can judge by the content of this directory (HTML files, images) that this can be an user directory that holds a site that's being exposed by Apache. But I'd say that doing this automatically with a script seems unreliable to me. Not to mention that for example you can have a public_html directory that is not an user directory, its name matching the default value for Apache UserDir setting being just a simple coincidence. Ideally, in order to judge about a directory if it's an UserDir, you'll need access to the configuration file of the web server. And normally you don't have it. Web hosting providers can put at most user-specific logs in your home directory.

To summarize: if you need to perform any actions with the user directory, have it come to your script as input data: command-line argument, setting from a config file etc, but do not try to guess it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.