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.

Changing DocumentRoot via cPanel API?

Discussion in 'General Discussion' started by Kadence, Jan 4, 2008.

  1. Kadence

    Kadence Member

    Joined:
    Nov 25, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Is there way to change the DocumentRoot of an account using cPanel, either during account creation or later on?

    Or is there some other way to have two cPanel accounts share a DocumentRoot?
     
  2. Kadence

    Kadence Member

    Joined:
    Nov 25, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Anyone know if this is possible in cPanel?
     
  3. Kadence

    Kadence Member

    Joined:
    Nov 25, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Does cPanel offer this in any way?
     
  4. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    You may change your doc root of an account by editing the httpd.conf.
     
  5. Kadence

    Kadence Member

    Joined:
    Nov 25, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Yes I know, but that isn't through cPanel, which can probably lead to problems and conflicts.
     
  6. johnmigen

    johnmigen Active Member

    Joined:
    Jan 19, 2008
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    6
    If you have root access to the server, you can try this.

    Service Configuration --> Apache Setup --> Include Editor --> Pre Virtual Host Include

    Paste these codes there and restart your apache, that would do

    # This is self created
    <VirtualHost ipaddress:80>
    ServerName domain.com
    ServerAlias www.domain.com
    ServerAdmin webmaster@domain.com
    DocumentRoot /home/changetheusername/public_html
    </VirtualHost>

    Note that you should put this in Pre Virtual Host, apache reads top down, if you put it in Post, apache will read the automatic generated codes.

    You might want to check your /etc/httpd/conf/httpd.conf for example of automatic generated virtualhost, copy them and amend servername, serveralias and documentroot.

    Hope this helps.
     
  7. johnmigen

    johnmigen Active Member

    Joined:
    Jan 19, 2008
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    6
    I was reading other threads, somehow the more correct way of doing it is to edit the user's file so that things get generated automatically after each apache rebuild.

    1. Locate the domain you're trying to edit in /var/cpanel/userdata/user
    2. Edit your file
    3. Run /scripts/ensure_vhost_includes --user=USER
     
    #7 johnmigen, Jan 19, 2008
    Last edited: Jan 20, 2008
  8. Kadence

    Kadence Member

    Joined:
    Nov 25, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Thanks johnmigen, the Pre Virtual Host Include method worked. The DocumentRoot in pre_virtualhost_1.conf overwrote the DocumentRoot in httpd.conf. The bare minimum pre virtual host entry necessary seemed to be:

    <VirtualHost ip.ip.ip.ip>
    ServerAlias domain.com
    DocumentRoot /path/to/newroot
    </VirtualHost>

    I couldn't get this method to work though, changing the 'documentroot:' value in the /var/cpanel/userdata/user/domain.com file didn't seem to have any effect. I also tried --all-users, and doing httpd restart and named -u named afterwards, but no go. This method does seem less 'hackish' than the other method, but I couldn't get it to work.
     
    #8 Kadence, Jan 23, 2008
    Last edited: Jan 23, 2008
  9. johnmigen

    johnmigen Active Member

    Joined:
    Jan 19, 2008
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    6
    I've tried the last method, but things seems more complicated. If you have suphp or phpsuexec running, you must set the user and group to be the same as the folder you are trying to serve out, else there would be an error.

    The include method seems to be more friendly, i agree totally.
     
  10. Kadence

    Kadence Member

    Joined:
    Nov 25, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Anbody know how to get the /var/cpanel/userdata/user method to work? Should there be any more steps than those described above?
     
  11. johnmigen

    johnmigen Active Member

    Joined:
    Jan 19, 2008
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    6
    After you edit the file, you need to run this /scripts/ensure_vhost_includes --user=USER

    and rebuild your apache conf

    that will do
     
  12. cathleen

    cathleen Registered

    Joined:
    Jun 16, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    modify cpanel user level documentroot?

    I modified subdomain.mysite.com file under /var/cpanel/userdata/myusr and updated the path to documentroot:

    then I did
    $ /scripts/ensure_vhost_includes --user=myuser
    Waiting for httpd to restart..............finished.

    httpd (/usr/local/apache/bin/httpd -k start -DSSL) running as root with PID 8509

    httpd started ok

    I then tried access subdomain.mysite.com and it is still pointing to the old path! What am I missing here?
     
  13. cathleen

    cathleen Registered

    Joined:
    Jun 16, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    re: modify cpanel user level documentroot?

    This is what's required to get it working:

    1. modify the "documentroot:" in your cpanel user subdomain file
    /var/cpanel/userdata/myusr/subdomain.mysite.com

    2. update user vhost conf file
    $ /scripts/ensure_vhost_includes --user=myuser

    3. rebuild apache conf
    $ /usr/local/cpanel/bin/build_apache_conf

    4. restart server in WHM (or however you restart)
    Main>>Restart Services>>HTTP Server

    test your subdomain.mysite.com and voila!
     
  14. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Assuming you did the server side updates correctly ...

    1. Clear your web cache and close browser

    2. Windows Systems:
    Code:
    1. Open Dos Prompt  ('CMD' from Start->Run)
    
    2. Type  'ipconfig /flushdns'
    
    3. Reopen your browser and see if you still have the old information
     
    #14 Spiral, Jun 16, 2009
    Last edited: Jun 16, 2009
Loading...

Share This Page