Changing DocumentRoot via cPanel API?

Kadence

Member
Nov 25, 2006
24
1
151
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?
 

jayh38

Well-Known Member
Mar 3, 2006
1,212
0
166
You may change your doc root of an account by editing the httpd.conf.
 

Kadence

Member
Nov 25, 2006
24
1
151
Yes I know, but that isn't through cPanel, which can probably lead to problems and conflicts.
 

johnmigen

Active Member
Jan 19, 2008
43
0
56
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?
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 [email protected]
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.
 

johnmigen

Active Member
Jan 19, 2008
43
0
56
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
 
Last edited:

Kadence

Member
Nov 25, 2006
24
1
151
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 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
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.
 
Last edited:

johnmigen

Active Member
Jan 19, 2008
43
0
56
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.
 

Kadence

Member
Nov 25, 2006
24
1
151
Anbody know how to get the /var/cpanel/userdata/user method to work? Should there be any more steps than those described above?
 

johnmigen

Active Member
Jan 19, 2008
43
0
56
Anbody know how to get the /var/cpanel/userdata/user method to work? Should there be any more steps than those described above?
After you edit the file, you need to run this /scripts/ensure_vhost_includes --user=USER

and rebuild your apache conf

that will do
 

cathleen

Registered
Jun 16, 2009
2
0
51
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?
 

cathleen

Registered
Jun 16, 2009
2
0
51
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!
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
I then tried access subdomain.mysite.com and it is still pointing to the old path! What am I missing here?
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
 
Last edited: