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.

Change document root

Discussion in 'General Discussion' started by mikealim, Jun 26, 2008.

  1. mikealim

    mikealim Registered

    Joined:
    Jun 26, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    I've been seeing a lot of this question in the thread but didn't find any answer.

    I want to change the document root of our primary domain from public_html to public/html/new_folder.

    Is there any way I can do this in Cpanel?
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    This functionality is not natively supported in cPanel at this time.

    You can do this for subdomains and add-on domains though.
     
  3. kgm

    kgm Registered

    Joined:
    Jul 1, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Can www be defined as a subdomain?

    It's a particular pain that cPanel doesn't allow the user to configure DocumentRoot for the primary domain. ISPs, reluctant to change httpd.conf, seem to recommend that you use Apache rewrite rules in public_html/.htaccess to change requests for www.mysite.com to become www.mysite.com/subdir - which works but has the downside that all the site's URLs now have "subdir" in their path unless you have some scripting to strip off what Apache added.

    Would the following work? The primary domain is actually mysite.com, so presumably I can use cPanel to define a subdomain named www.mysite.com. And since it's a subdomain, I can control its DocumentRoot via cPanel. And, finally, to deal with requests directed to mysite.com, I can add some rewrite rules to public_html/.htaccess to convert requests to mysite.com to www.mysite.com. Or maybe I can set up a redirect to do this last bit?

    I suspect there is some obvious reason why this wouldn't work. What is it?

    Thanks.
     
  4. PlatinumServerM

    PlatinumServerM Well-Known Member
    PartnerNOC

    Joined:
    Jul 10, 2005
    Messages:
    397
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    New Jersey, USA
    cPanel Access Level:
    Root Administrator
  5. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    As PlatinumServerM told you in a previous post above, you can make
    this change by altering the VirtualHost information for the account in
    the main Apache configuration (/usr/local/apache/conf/httpd.conf) ...

    The question is not so much "if you can" as "if you should"?

    I have at various times needed to change the default document root
    to different folders for one reason or another and it works fine in doing
    so but my experience has been that you tend to forget about such
    custom changes and can run into some major headaches later when
    trying to maintain compatibility or going through software updates.

    A better suggested way of doing this may be to create a symlink on
    the acount much the same way "www" by default points to "public_html"
    to maintain compatibility with users who are more used to other servers
    that use "www" as the root web account folder. You can create the
    same kind of symlink and direct that to whatever folder structure you wish
    and accomplish the same thing instead of updating Document Roots or
    implementing complicated web redirects with mod_rewrite commands, etc.

    In example:
    Code:
    # cd /home/(username)
    # mkdir ./public 
    # mkdir ./public/html
    # ln -s ./public_html ./public/html/new_folder
    
    Now I don't know if you are requesting this change because you do not
    want "public_html" to appear in the URL or some other reason. If the former
    is the case, then I would be pleased to let you know that you have made a
    wrong assumption (and a fairly common mistake make by most new users)
    assuming FTP structure where you upload your files is the same as the
    web structure when you view your pages but is actually one level higher.

    More specifically ...

    When uploading files to /public_html, your files are not located at /public_html
    out on the internet, on the web, but rather at the root (/) of your domain.

    In FTP upload example: Uploading 'test.html' to /public_html folder

    This file on the web, would be: http://www.yourdomain.com/test.html

    A lot might think (incorrectly), the file would be at http://www.yourdomain.com/public_html/test.html
    but this idea is actually wrong and a bad assumption made by many new users.
     
    #5 Spiral, Jul 1, 2009
    Last edited: Jul 1, 2009
  6. kgm

    kgm Registered

    Joined:
    Jul 1, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I would if I could

    Not unreasonably, my ISP doesn't give me access to httpd.conf. What is less reasonable on their part is that they are unwilling to make the one-line change for me.
     
  7. kgm

    kgm Registered

    Joined:
    Jul 1, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    The reason is that I have developed a new version of my site in /public_html/mynewsite. My ISP are unwilling to change httpd.conf for me. Instead, they recommend I use rewrite rules in /public_html/.htaccess to change requests for www.mysite.com to be www.mysite.com/mynewsite. This achieves the redirect but, of course, includes "mynewsite" in the resultant URLs seen by the visitor. Not what I want.

    The symlink idea would be nice, assuming I have permission. But doesn't that require that the ISP have enabled FollowSymLinks in Apache?
     
  8. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Unless the server administrator hardened down the security on their server
    to disallow this, the server probably still has "FollowSymLinks" enabled still
    and / or probably still allows you to override to do this anyway.

    (Yes, that's a whole pet peeve in itself me as a security administrator! ;))

    Anyway, no you normally don't have to be an administrator to set up the
    symlinks on standard default cPanel server installs but you will likely
    be restricted to just operating within your own account which is how
    it is supposed to be in the first place, right? *EVIL GRIN* :D

    On a different note, sounds like you are working more with subdomain
    addresses instead of domain addresses from your posts but ignoring that,
    you may want to set things up as "Addon" domains instead of as "subdomains"
    or "parked" domains as you have more control as far as DocumentRoot
    locations and sets up it's own separate FTP login too. Just a thought.
     
Loading...

Share This Page