The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

DocumentRoot query

Discussion in 'General Discussion' started by martyf, Oct 17, 2010.

  1. martyf

    martyf Member

    Joined:
    Oct 17, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I'm new to cPanel so still finding my way around, and just had a query regarding the "public_html" folder.

    For one of my applications, it has folders that sit above the root folder.

    For example, www.domain.com would actually be pointing to a "web" folder: eg
    /home/username/public_html/web

    This way, there would be other folders in public_html, eg
    /home/username/public_html/classes/
    /home/username/public_html/config/
    etc
    all of which are not visible via a URL.

    My question is:
    Should I be looking at how to use the Includes for Apache configuration through WHM, or should I just create these other folders (i.e. classes, config, etc) manually using the cPanel File Manager - eg:
    /home/username/classes/
    /home/username/config/
    /home/username/public_html/

    The second way doesn't require any additional changes to Apache, but just after people's thoughts or advice on which way is better, and why?

    Cheers,
    Marty
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    If you place something inside of public_html, it is visible via the web due to the fact public_html is the location that is the document root. If you want the folders not to be available to somehow get to the content, you'd ideally need to place them at /home/username location instead and then use includes for the path. That's actually how Rails sets up its environment with the public folder (normally symlinked or redirected to public_html) only available to the world and the rest of the folders in /home/username or /home/username/rails_apps/appname/folders location in cPanel's setup.
     
  3. martyf

    martyf Member

    Joined:
    Oct 17, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks cpaneldanielle - and that setup I understand.

    I'm coming from a Plesk environment (shared host) where my host wouldn't place folders above public_html (i.e. in the case, under "username"). They changed the way public_html worked, and created a new folder within public_html that acted as the "new" public_html. So their setup was:
    public_html/web/
    where "web" is the "new" public_html... accessing www.domain.com would access files in the "web" folder.

    So back to the original question, is it worth changing the DocumentRoot to mimic what my previous host has done?

    Or is it safe with cPanel to create folders above public_html, in the /home/username path, as initially suggested?
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    If you like that setup, you can change the documentroot to be /home/username/public_html/web if you want, but to do that on a main domain, you'll need to edit the file path for the documentroot in /var/cpanel/userdata/username/domain.com file, then run /scripts/rebuildhttpdconf and restart Apache.

    It isn't safe to create folders that should be private inside public_html. As I mentioned, they aren't then private. Anyone could gain access to them unless you plan to password protect them, which would be a huge hassle compared to simply having them outside the documentroot
     
  5. martyf

    martyf Member

    Joined:
    Oct 17, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Can this be done using the Post VirtualHost include too (i.e. overwriting the DocumentRoot)? Or just editing the domain.com file?

    This may be a strange question, but if the DocumentRoot has been changed to say /public_html/web/, then that would mean that folders within /public_html/ are private? Or have I missed something?


    Edit: And to ask part of the original question again - is there any harm in putting these other folders "classes", "config", etc, above public_html for an account, so the structure would look like this:
    /home/username/classes/
    /home/username/config/
    /home/username/public_html/
    This leaves public_html as it is (i.e. no Apache config changes), but just wondering if cPanel "likes" having these other folders created outside of public_html.
     
    #5 martyf, Oct 18, 2010
    Last edited: Oct 18, 2010
  6. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    I'd already suggested in my initial reply to put the folders outside public_html to ensure they are private, so if you don't want to modify the documentroot, you'd want to put them in /home/username

    For the question on editing the include files, you cannot change the documentroot in an include file. It's an already set entry. You'd have to edit it as I suggested in /var/cpanel/userdata/username/domain.com and rebuild Apache with /scripts/rebuildhttpdconf, then restart Apache.

    If you edit the documentroot to be /home/username/public_html/web and then put folders into /home/username/public_html for classes and so on, then they will be private. What isn't private is putting files or folders into the documentroot, whatever the document root happens to be.
     
  7. martyf

    martyf Member

    Joined:
    Oct 17, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks for the reply cpanelDanielle. Yes, I am aware that any thing in public_html is public - that's never been the issue or question.

    The key question still isn't being answered though.

    Two scenarios:

    Scenario 1: Leave DocumentRoot as it is
    Is there any harm in putting these other folders "classes", "config", etc, above public_html for an account, so the structure would look like this:
    /home/username/classes/
    /home/username/config/
    /home/username/public_html/
    This leaves public_html as it is (i.e. no Apache config changes), but just wondering if cPanel "likes" having these other folders created outside of public_html.

    I say "likes", because my previous host (shared host) didn't want to do this - they changed the DocumentRoot so that public_html/web was public, and I put the other folders in public_html - given "web" was the DocumentRoot, this kept the other folders private. This was on a Plesk environment.

    Scenario 2: Change DocumentRoot to something like /home/username/public_html/web/
    Is there any benefit in doing this, or is Scenario 1 considered best-practice for this issue?



    So I'm looking for clarification as to whether it is good-practice to create folders outside of public_html (Scenario 1), or better to change the DocumentRoot (Scenario 2), and whether cPanel has any problems or conflicts with either scenario.
     
  8. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    I wouldn't suggest something that didn't work with cPanel, and I've twice suggested to put them outside public_html at /home/username, so I apologize if that still is not clear :)

    I see absolutely no reason to change the documentroot when putting them in /home/username (as I've mentioned repeatedly) would work.

    It's up to you what you want to do. cPanel is not going to care one way or the other. There is no "like" or "not like" here, there's what's easy and what isn't easy. The method I've suggested is the easiest way (using /home/username). It's up to you if you want to do it differently.

    I'll let someone else take a shot at answering these questions if you still have any in case you need another point of view.
     
  9. martyf

    martyf Member

    Joined:
    Oct 17, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks Danielle - this is what I was needing to hear.

    Based on past experience with the shared host (who may have just been too lazy or too strict), I was told this was not possible, hence needed the clarification.

    Many thanks indeed :)
     
Loading...

Share This Page