Default Subdomain Directory

typicalGtaTG

New member
Joined
Jun 26, 2021
Messages
3
Hi,
I just started using DirectAdmin for the first time and see that when I make a new subdomain, the subdomain root directory is set to be inside the root domain's directory under public_html. This concerns me a lot because not only are people able to access that subdomain using example.com/subdomain but also it's hard to manage site files that way and makes for a lot of clutter.
I wanted to ask if it's possible that I change the default path to be domains/subdomain/public_html without having to do that for every subdomain manually for every domain.
 
It's not really hard at all to manage site files that way at all.
But I understand if you have multiple subdirectory's it can get confusing.

So yes it's possible to change the default location of subdomains. You have to create some custom changes though.

It can be done for the whole server, you have to change apache configs for that.

For 1 account it can be done like this:

There is also a GUI for it in Directadmin itself:
 
It's not really hard at all to manage site files that way at all.
But I understand if you have multiple subdirectory's it can get confusing.

So yes it's possible to change the default location of subdomains. You have to create some custom changes though.

It can be done for the whole server, you have to change apache configs for that.

For 1 account it can be done like this:

There is also a GUI for it in Directadmin itself:
I can make a backup of the current apache configs and change it, I'm not sure where I should look for it tho.
 
Please don't quote complete messages.

It's mentioned in the second link:
Dashboard > Sub-Domains Setup > Document Root Override

Upon clicking Sub-Domains Setup, you should see an option to edit the document root (an edit icon that resembles a pencil), and upon clicking this option, will be taken to the Document Root Override path noted above.

I'm not sure if it can be done for the whole server by default, maybe somebody else knows.
 
I was able to achieve this by making a custom script and modifying the DOCROOT in the vhost template.
 
This might be helpfull too. Moves the main domain into a difirent directory, instead of the subdomains.

 
Hello all,
i apologize for reviving this topic..
is there a way to achieve this server-wide, from the admin part of DA, so that it applies to all users/domains on the server?
Thank you!
 
Last edited:
Hello.
We don't like reviving, but this is not really reviving, not even a year old. ;)

As said in post #5 it can be done by changing the docroot in the vhost template.
You have to take care it will not be overwritten then, so you have to use a custom directory.

I found a nice manual, use the templates you need. And ofcourse use at your own risk. I don't even understand the need for using another name.:)
 
Thank you for your response!

i still have a problem: when i add a subdomain, say sub.domain.com, through the DA web interface, DA still creates a folder inside the public_html directory of the main domain, even though the http.conf file puts the DocumentRoot in the correct new place:
/home/USER/domains/DOMAIN/subdomains/SUB

Here's what i did..
in Terminal, as root:
Code:
cd /usr/local/directadmin/data/templates
mkdir custom
cp virtual_host*_sub.conf custom
chown -R diradmin:diradmin custom

Then edited the 4 files:
in virtual_host_secure_sub.conf, virtual_host_sub.conf, virtual_host2_secure_sub.conf and virtual_host2_sub.conf:
Replaced all instances (using RegEx) of
Code:
`HOME`/domains/`DOMAIN`/p.*_html
With:
Code:
`HOME`/domains/`DOMAIN`/subdomains/`SUB`
And all instances of:
Code:
|DOCROOT|/|SUB|
With:
Code:
|DOCROOT|

Then, ran the following commands in Terminal:
Code:
echo 'action=rewrite&value=httpd' >> /usr/local/directadmin/data/task.queue
mybuild rewrite_confs
/usr/local/lsws/bin/lswsctrl reload

(i'm using LiteSpeed Enterprise, which uses httpd config files rather than the OpenLiteSpeed files)

So now, when i create a subdomain, the file in:
/usr/local/directadmin/data/users/USER/httpd.conf
shows the correct new DocumentRoot, but the DA panel still creates the folder in the old location..

i greatly appreciate all the help with this, and would be so grateful if you could help me overcome this last obstacle!

EDIT: quick note: i waited a couple minutes after the file /usr/local/directadmin/data/task.queue disappeared before issuing
mybuild rewrite_confs
also, mybuild is a bash alias to the /usr/local/directadmin/custombuild/build
 
Last edited:
Thank you, i much appreciate the help!

I've been pouring over those docs, but i can't find the problem..

it's so odd that the user httpd.conf file comes out exactly as i want it, but the panel still creates the directories in the default spot..
there's got to be some script that the panel runs to create those directories..

i've been trying to find that, but, so far, no luck..

(i looked in /usr/local/directadmin/scripts/ but that would've been too easy🤪)
 
I think the only way to loose the subdirectory for subdomains is to create the subdomain as domain, so that is not something which can be done serverwide. The subdomain content must be residing somewhere.
 
My guess is that this is because the vhost templates and the directory creation is not linked in any way. Probably the only way you can automate this for new setups is to use a custom script (https://www.directadmin.com/features.php?id=445). During create, you'd have to remove the directory you don't want (but check that it's empty first, it might have the same name as an actual subdirectory of the main domain!), and create the one you *do* want. Then for destroy, you would need to delete your custom directory and its contents if that's what the user wants.

I'd love to see an option somewhere that would default to creating subdomain docroots outside of the main domain's docroot.

(Sorry for the slight necro, but I was recently looking into this myself, and came across this. :))
 
Back
Top