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.

one document root, best way to do this?

Discussion in 'General Discussion' started by ozzieonline, Jul 12, 2014.

  1. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Hello everyone,

    English is not my mother language, so if my question is unclear, please say so.

    I want to reinstall my VPS in a better way than it is right now. What I want to accomplish is that all (new) domains when I add them, automatically point to the same document root (the same folder).

    How do I do this now? I use one "main" user. I use this user to log in to cPanel and when I add a new domain I add it as an "add-on domain". This way I can point all add-on domains to the same document root.

    However, Im wondering if there is somehow a better solution to accomplish this. I'd rather add each domain as a "normal" domain, instead of an add-on domain.

    Is there a solution to do this? For example change a default vhost template or something?

    Actually it should be like this. I log in to WHM as root. Then when I create a user, the document root of this user should always be the same. Can it be done?

    Once again, if my question is unclear, please say so!
     
    #1 ozzieonline, Jul 12, 2014
    Last edited: Jul 12, 2014
  2. iserversupport

    iserversupport Well-Known Member

    Joined:
    Nov 4, 2013
    Messages:
    91
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    cPanel Access Level:
    Root Administrator
    You can create separate user for each domains from WHM

    Home »Account Functions »Create a New Account
     
  3. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Thanks for replying.

    I understand what you are saying, but my question is... can I somehow point EACH domain to the same document root (folder). So when I create a new account and a new domain for John, I want the document root to be folder X. Then when I create a new account and a new domain for Mike, I want the document root to be this same folder X. Is that possible?
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    You can modify the document root for a domain name by editing the "documentroot" entry in the appropriate cPanel user data file:

    Code:
    /var/cpanel/userdata/$username/$domain.com
    Then, rebuild the Apache configuration file via:

    Code:
    /scripts/rebuildhttpdconf
    However, if you want all domain names to have the same document root upon account creation, then you may want to modify the Apache templates per the instructions here:

    Apache - Custom Templates

    Thank you.
     
  5. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Thanks Michael!

    Doesn't this file "/var/cpanel/userdata/$username/$domain.com" get changed on cPanel/WHM/Apache updates? Will my adjustments be forever preserved?

    I once did some tweaking of the Apache templates to find out a whole lot later that some of my adjustments disappeared due to a software update :-s

    Well ehhh... the link you gave me says:

     
    #5 ozzieonline, Jul 15, 2014
    Last edited: Jul 15, 2014
  6. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,455
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    That shouldn't have happened.
     
  7. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Correct, shouldn't have... but it did.

    But is what I want possible?

    cPanelMichael told me to change /var/cpanel/userdata/$username/$domain.com, but the manual warns that these files should not be changed... so that's strange isn't it?
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  9. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Thanks Michael. My last question... how would I do this server-wide. So not domain-based. So when I add a new domain (from different users) the document root is always the same. What's the best way to accomplish that, without the risk my adjustments are being overwritten?
     
  10. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Here is a quote from my previous response:

    Thank you.
     
  11. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Well, I tried that before but could not accomplish it. So that's why I was hoping you could give me some good advice which file to change and how.
     
  12. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You could also setup a post account creation hook that modifies the "documentroot" value in the /var/cpanel/userdata/$username/$domain.com file after the account is created. Information on script hooks is available at:

    Script Hooks - Intro

    You may want to consult with a software developer if you need the full script developed for you.

    Thank you.
     
  13. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    I'd rather try the template approach... but I wonder which template exactly I have to modify, and how... any advice on that?
     
  14. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You want it to apply to all VirtualHosts, so this part of the document I provided:

    Custom Templates That Will Apply To All VirtualHosts

    Note that you may need to consult with a system administrator for assistance if you are not comfortable making such custom changes.

    Thank you.
     
  15. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    I understand I'll have to use a local version of te vhost, but what if cPanel updates and changes the default vhost (on which my local version is based). Will things go wrong then because my local vhost is not up to date anymore? Or is that impossible?
     
  16. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    The template is connected to the version of Apache, so that's not going to be an issue. You could always just complete the process over again in the event you upgrade to a newer version.

    Thank you.
     
  17. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    So what you're saying is whenever I update Apache I also must update the local vhost?
     
  18. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    No, if you change the version of Apache installed on your system, you must make the change to the template relative to the version of Apache installed. There are different paths to the template, depending on the version of Apache installed, as listed in the documentation.

    Thank you.
     
  19. ozzieonline

    ozzieonline Well-Known Member

    Joined:
    Dec 20, 2012
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Ok thanks Michael, I think I understand now.
     
Loading...

Share This Page