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 site root directory

Discussion in 'General Discussion' started by enigmas, Jul 2, 2010.

  1. enigmas

    enigmas Registered

    Joined:
    Jul 2, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    I face the following issue, I have a hosted domain and my default root site directory is /public_html/ the problem is that I register several domains, with the site addon option from cpanel, which all of them have the root site directory in public_html, I want to change the site root directory of the primary domain to something like /public_html/primary, in this way all of my domains will have his own directory in /public_html.

    I've managed to trick the apache server with a .htaccess rule to rewrite the url from www.primary.co/primary to www.primary.co, at this moment I've faced another issue with the cgi-bin engine, I've solved that also with +execCGI rule on the .htaccess, but now the cgi binary (cgiemail) is tricked by my rewrite rule and doesn't know to get his template file.

    Does any one have a solution to change the default /public_html root site or how do i instruct the cgiemail to get the right path?

    .htaccess in /public_html/
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} primary.co
    RewriteCond %{REQUEST_URI} !^/primary
    RewriteRule ^(.*)$ primary/$1 [L]
    .htaccess in /public_html/primary/cgi-bin/
    Code:
    Options +ExecCGI
    SetHandler cgi-script
    In conclusion my /public_html/ should contain the following directories:
    primary (main domain)
    secondary1 (addon domain1)
    secondary2 (addon domain2)
    secondaryn (addon domainn)

    Regards,

    Solved the issue, wrong sintax of the cgiemail:

    wrong:
    Code:
    cgi-bin/cgiemail/template
    good:
    Code:
    cgi-bin/cgiemail/primary/template
    Hope this info will help someone.
     
    #1 enigmas, Jul 2, 2010
    Last edited: Jul 2, 2010
  2. Siteman

    Siteman Member

    Joined:
    Nov 15, 2008
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
  3. madaboutlinux

    madaboutlinux Well-Known Member

    Joined:
    Jan 24, 2005
    Messages:
    1,052
    Likes Received:
    2
    Trophy Points:
    38
    Location:
    Earth
    Not sure about the Google indexes but to change the DocumentRoot of a domain, you need to edit the Apache configuration file and edit the value of "DocumentRoot" parameter in the domains VirtualHost entry. Edit the apache configuration

    and set the DocumentRoot of the domain as

    Save the file and restart the httpd service. BTW, if you don't have root access to your server, ask your hosting provider to change it for you. It's a 2 minute task and hosting provider shouldn't deny your request.
     
  4. enigmas

    enigmas Registered

    Joined:
    Jul 2, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I agree with you, but on hosted domain server you not always have access to the Apache configuration, then the only option is to use .htaccess.
     
  5. enigmas

    enigmas Registered

    Joined:
    Jul 2, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Depends on what do you want to do, for example, if you use the site addon from cPanel, then your url will be www.secondary1.com, but if you use a forward than the rewrite rule should be used.

    Sincerely I didn't understood your question.
     
  6. Miraenda

    Miraenda Well-Known Member

    Joined:
    Jul 28, 2004
    Messages:
    242
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Coralville, Iowa USA
    This will not stay on Apache rebuilds as you cannot directly edit the lines in /etc/httpd/conf/httpd.conf in this way in cPanel. Such manual edits disappear on every EasyApache recompile (/scripts/easyapache) or every Apache rebuild (/scripts/rebuildhttpdconf) that someone runs on the machine. It even has this warning above every single VirtualHost section in that file:

    Code:
    # DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED 
    TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.
    To properly edit the DocumentRoot, you would instead go to /var/cpanel/userdata/username/ location (replace username with the actual cPanel username for the account), then edit the file domain.com where domain.com is your primary domain name.

    You will see something like this in that file:

    Code:
    documentroot: /home/username/public_html
    You will also see the cgi-bin area in this section:

    Code:
    scriptalias:
      -
        path: /home/username/public_html/cgi-bin
        url: /cgi-bin/
    Simply change both to the right path, then save the file. At that point, copy your existing httpd.conf file, rebuild Apache, then restart Apache. Your site will then start serving from the new document root.

    Here are the commands to do those:

    Code:
    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak100704
    /scripts/rebuildhttpdconf
    /etc/init.d/httpd restart
    You can also look at /etc/httpd/conf/httpd.conf at that point to see it now has the changed DocumentRoot line and cgi-bin path.
     
    #6 Miraenda, Jul 5, 2010
    Last edited: Jul 5, 2010
Loading...

Share This Page