webhost - public_html folder

March 26, 2016 648 views
Apache LAMP Stack Ubuntu

Hi all, i'm new about the "world" of web hosting. So i decided to start with a small droplet to create a webserver that hosts multiple website. So i decided to install LAMP and some test folder under the path: /var/www/html

The structure is like this:


You can see i don't use the suggested "public_html" folder.
This because (and for sure im wrong) i don't see the advantages to have something like this:


Where are the advantages to use that folder ? every provider uses that so of course there is a reason (probably about to be more safe)

Can someone give me some basic example why this folder is necessary?

thank you

1 Answer

The primary reason you will often find a directory structure like that is that the web host may be storing other types of files for the site that they want associated with the site, but not shared publicly. For instance, on some web hosts you will have a log directory where the logs for just your domain are stored. This way the webhost can give FTP access to the /var/www/html/site1/ directory to the end user and they can access all files related to their service.

One of the original reasons that this directory structure became common is that back in the 90's when the primary coding language for websites was Perl/CGI scripts, it was common practice to keep these files in a cgi-bin directory outside the main web root rather than having executables within the web root. This is no longer a concern today but the convention lives on.

  • thank you for your reply. so it's could give more flexibility.
    for example i could give to the end user that directory:


    but not this one:


    in that way under the same website the public_html folder is for the end-user where he can does everything he wants, but the backup folder is private and just an "administrator" can access inside it.

    it was just an example to give an idea about "more flexibility" i understand right? thank you

    • Yes. That's the general idea. There might be stuff associated with an individual site's "account" that belong outside the web root directory (shouldn't be public).

      To actually implement this type of system with the SFTP service that droplets come with you can edit your sshd configuration to include a 'Match User' block specifying the user name and with a ChrootDirectory directive in that block pointing to the directory you want the user to remain under.

Have another answer? Share your knowledge.