mikealim

Registered
Jun 26, 2008
1
0
51
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?
 

kgm

Registered
Jul 1, 2009
3
0
51
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.
 

PlatinumServerM

Well-Known Member
PartnerNOC
Jul 10, 2005
400
3
168
New Jersey, USA
cPanel Access Level
Root Administrator
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.
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
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:

kgm

Registered
Jul 1, 2009
3
0
51
I would if I could

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.
 

kgm

Registered
Jul 1, 2009
3
0
51
<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?
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
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* :D

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.