Mobile app version of vmapp.org
Login or Join
Phylliss660

: How to change document root of main domain in cPanel shared host? I am in a shared host that I have basic cli access. Inside public_html/ I host several addon domains, each in its own dir.

@Phylliss660

Posted in: #Apache #Cpanel #Server #SharedHosting

I am in a shared host that I have basic cli access.

Inside public_html/ I host several addon domains, each in its own dir. Is it possible to make my main domain's document root inside another folder to achieve the following structure?

public_html/
--maindomain_root/
--othersite1_root/
--othersite1_root/


instead of:

public_html/
--maindomain_file1
--maindomain_file2 (..etc)
--othersite1_root/
--othersite1_root/

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Phylliss660

4 Comments

Sorted by latest first Latest Oldest Best

 

@XinRu657

For changing the main/primary domain, you will need to have root SSH access and be able to locate and edit the following file (replacing your user & domain info):

/var/cpanel/userdata/USERNAME/DOMAIN.COM



Once you have opened the file, look for the following line:

documentroot: /home/USERNAME/public_html
Modify the location according to your needs. Save it and exit.
Rebuild the Apache conf and restart Apache:

/scripts/rebuildhttpdconf

service httpd restart


The change will be immediate. Simply clear your browser cache and force refresh the page!

10% popularity Vote Up Vote Down


 

@Correia994

Sorry my question is actually wrong because I had the misconception that all document roots must live inside public_html/. I just moved them outside, and now public_html/ is just the doc root for my main domain. So I avoided to have scattered files and every site is in its own dir.

10% popularity Vote Up Vote Down


 

@Holmes151

You can add an .htaccess file if not existing previously.

If the file already exists then add below code to it; Don't overwrite previously existing .htaccess file without taking BACKUP or renaming.

public_html/
--.htaccess
--maindomain_root/
--othersite1_root/
--othersite2_root/


Content for .htaccess

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$
RewriteRule ^(/)?$ maindomain_root [L]

RewriteCond %{HTTP_HOST} ^(www.)?othersite1.com$
RewriteRule ^(/)?$ othersite1_root [L]

RewriteCond %{HTTP_HOST} ^(www.)?othersite2.com$
RewriteRule ^(/)?$ othersite2_root [L]


Please note one important thing - Having addon domains which are non-related in a fashion listed above will lead to mixed urls in response to search engine queries UNLESS you define your indexable content and sitemap carefully.

10% popularity Vote Up Vote Down


 

@Harper822

In httpd.conf (which is usually located in /usr/local/apache/conf in a linux box with cpanel), you'll find a number of sections beginning with <virtualhost. Inside each one you'll see a line for "DocumentRoot".

The path shown next to it is what the system will use to find an index file when a user tries to access the domain name itself as a url.

Also, to confirm you're dealing with the right domain, look for "ServerName" entries or even the domain name itself. After all, each individual block of text beginning with <virtualhost contain settings specific to only one domain.

When the settings are changed, restart apache gracefully. You may want to follow the instructions at the top of the configuration file that cpanel puts in so that you can retain the changes in the configuration.

Another option which is less flexible is to try to enter user account management or even the tweak settings in the WHM, but I don't play with WHM too much since I prefer the shell.

If you don't want to play with apache configuration too much, then what you could do is create a folder where you want the documents to be located and create a symbolic link.

In linux, you'd type:

ln -s /path/to/new/folder /home/domain

where "/home/domain" is your current document root for the domain you want to change. Just make sure you set the permissions of the symbolic link and the new folder correctly or users will find their access being denied.

As always, test your setup.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme