Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    1

    Unhappy Change document root

    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. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,720
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by mikealim View Post
    ...

    Is there any way I can do this in Cpanel?
    This functionality is not natively supported in cPanel at this time.

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

  3. #3
    kgm
    kgm is offline
    Registered User
    Join Date
    Jul 2009
    Posts
    3

    Default 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. #4
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Jul 2005
    Location
    New Jersey, USA
    Posts
    397

    Default

    If you really must change it, then you can manually change it by editing the virtualhost of that domain in the httpd.conf and change the document root path there.

  5. #5
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Default

    Quote Originally Posted by mikealim View Post
    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?
    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.
    Last edited by Spiral; 07-01-2009 at 02:15 PM.

  6. #6
    kgm
    kgm is offline
    Registered User
    Join Date
    Jul 2009
    Posts
    3

    Default I would if I could

    Quote Originally Posted by PlatinumServerM View Post
    If you really must change it, then you can manually change it by editing the virtualhost of that domain in the httpd.conf and change the document root path there.
    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. #7
    kgm
    kgm is offline
    Registered User
    Join Date
    Jul 2009
    Posts
    3

    Default

    Quote Originally Posted by Spiral View Post
    <snip>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. <snip>
    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. #8
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Wink

    Quote Originally Posted by kgm View Post
    The symlink idea would be nice, assuming I have permission. But doesn't that require that the ISP have enabled FollowSymLinks in Apache?
    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*

    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.

Similar Threads & Tags
Similar threads

  1. How to change the document root for my website in cpanel?
    By ker in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 05-05-2010, 01:08 AM
  2. Change the "document root" of a domain
    By ramzez in forum New User Questions
    Replies: 8
    Last Post: 12-09-2008, 01:54 AM
  3. Suggestion: Add Option to Change Document Root
    By StanleyS in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 12-04-2008, 12:00 PM
  4. change default document root
    By amaltemara in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 12-19-2007, 10:18 PM
  5. Document Root?
    By kozmik in forum New User Questions
    Replies: 2
    Last Post: 11-23-2007, 02:28 PM
Tags for this Thread
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube