Ability to easily point subdomain document root

dmacleo

Verified User
Joined
Jun 21, 2012
Messages
653
Please try to make this work like cpanel does, the ability to create a new folder for the subdomain or point to an existing folder.
 
I wonder if it's needed:
the ability to create a new folder for the subdomain or point to an existing folder.
If you create a subdomain name, a folder with that subdomains name is created. So this option is already present.

If dmacleo (and you) ment something else, I think you have to clarify what you exactly mean.
 
Lets say two examples:
1. Create new domain and new feature - ability to point web-root folder (default is public_html, but for example symfony and symfony2 need to be public_html/web. For now I make it works by change htaccess or by manually change virtualhost - it is not so simple and user-friendly method)
2. As above but for subdomains. Sometimes it`s not good to allow access by domain.com/subdomain to subdomain.domain.com. Of course I can redirect by rewrite in htaccess BUT - it is not so user-friendly and easy.

If is problem with security maybe it should be limited to /home/user/domains/domain.com/(customized path) and from this point it can be customized or one folder below...

If it still not so clear please write...
 
I wonder if it's needed:

If you create a subdomain name, a folder with that subdomains name is created. So this option is already present.

If dmacleo (and you) ment something else, I think you have to clarify what you exactly mean.

pointing to existing folder is one of the 2 items I mentioned, thats why I said "or."
say I use a domain/uploads folder to run a file/download center but in order to work around cloudflare 50mb upload limit I need to run my upload url off a different url pointing to the same existing folder already in use.
and cpanel is much more flexible with all subdomain and dns stuff, would be nice to EDIT a dns record w/o having to delete and recreate it.
 
Yes but the describtion was not clear enough.

What you would like to have is an option to set a custom root folder for subdomains.
That's easyer said and is a better definition.

+1 for such option.
 
bumping this again.
I have asked before and people seem to not care but if average user wants to create a subdomain and point to an existing folder for whatever reason he wants the server admin should not have to get involved and add to the custom httpd.conf.
people here may not like cpanel but at least there an average user can do this (its needed for cdn usage) on their own. during the creation of the subdomain the choice of folder is shown (defaults to sub name) and user can either leave as is or point to existing.
and the present method to do this, to be blunt, sucks.
not trying to ruffle any feathers but come on, why should a server admin need to be involved for this?
 
Dear DIrectAdmin support or Martynas ;-). It's any chance to make it work?
This will make our life will be easier... ;-)
 
+1 to this. We would like subdomains to be placed in a directory on this path: /home/USERNAME/subdomains or on this path: /home/USERNAME/domains/subdomains

But we also need a way to automatically convert all existing subdomains to the new path.

We do not like to have subdomains placed inside public_html directory for it's top level domain. That only causes trouble for .htaccess files, and confusion for customers.
 
Last edited:
+1 to this. We would like subdomains to be placed in a directory on this path: /home/USERNAME/subdomains or on this path: /home/USERNAME/domains/subdomains

But we also need a way to automatically convert all existing subdomains to the new path.

We do not like to have subdomains placed inside public_html directory for it's top level domain. That only causes trouble for .htaccess files, and confusion for customers.

To achieve this, you can do the following to place subdomains under /home/username/domains/domain.com/subdomains/SUB:

Code:
cd /usr/local/directadmin/data/templates
mkdir -p custom
cp -p virtual_host2*sub.conf custom/
cd custom
perl -pi -e 's#`HOME`/domains/`DOMAIN`/private_html#`HOME`/domains/`DOMAIN`/subdomains/`SUB`/private_html#' virtual_host2_secure_sub.conf
perl -pi -e 's#`HOME`/domains/`DOMAIN`/public_html/`SUB`/cgi-bin/#`HOME`/domains/`DOMAIN`/subdomains/`SUB`/public_html/cgi-bin/#' virtual_host2_secure_sub.conf
perl -pi -e 's#\|DOCROOT\|/\|SUB\|#\|DOCROOT\|#' virtual_host2_secure_sub.conf
perl -pi -e 's#`HOME`/domains/`DOMAIN`/public_html#`HOME`/domains/`DOMAIN`/subdomains/`SUB`/public_html#' virtual_host2_sub.conf
perl -pi -e 's#`DOCROOT`/`SUB`/cgi-bin/#`DOCROOT`/cgi-bin/#' virtual_host2_sub.conf
perl -pi -e 's#\|DOCROOT\|/\|SUB\|#\|DOCROOT\|#' virtual_host2_sub.conf

Add the following content to /usr/local/directadmin/scripts/custom/subdomain_create_post.sh (chmod the script to 755):
Code:
#!/bin/sh
mkdir -p /home/$username/domains/$domain/subdomains/$subdomain
chown $username:$username /home/$username/domains/$domain/subdomains
chown $username:$username /home/$username/domains/$domain/subdomains/$subdomain
mv -f /home/$username/domains/$domain/public_html/$subdomain /home/$username/domains/$domain/subdomains/$subdomain/public_html
mv -f /home/$username/domains/$domain/private_html/$subdomain /home/$username/domains/$domain/subdomains/$subdomain/private_html
exit 0;

Move all current subdomains to correct directories. Copy the following code to move_subdomains.sh, save and execute it (sh move_subdomains.sh):
Code:
#!/bin/sh 
USERSDIR=/usr/local/directadmin/data/users
for USER in `ls ${USERSDIR}`; do
{
          for DOMAIN in `cat ${USERSDIR}/${USER}/domains.list`; do
          {
                              for SUB in `cat ${USERSDIR}/${USER}/domains/${DOMAIN}.subdomains`; do
                              {
                                NEWDIR=/home/${USER}/domains/${DOMAIN}/subdomains/${SUB}
                                OLDDIR_PUBLIC=/home/${USER}/domains/${DOMAIN}/public_html/${SUB}
                                OLDDIR_PRIVATE=/home/${USER}/domains/${DOMAIN}/public_html/${SUB}
                                mkdir -p ${NEWDIR}
                                chown ${USER}:${USER} /home/${USER}/domains/${DOMAIN}/subdomains
                                chown ${USER}:${USER} ${NEWDIR}
                                if [ -d ${OLDDIR_PUBLIC} ]; then
                                  echo "Moving ${OLDDIR_PUBLIC} to ${NEWDIR}/public_html..."
                                  mv -f ${OLDDIR_PUBLIC} ${NEWDIR}/public_html/
                                fi
                                if [ -d ${OLDDIR_PRIVATE} ]; then
                                  echo "Moving ${OLDDIR_PRIVATE} to ${NEWDIR}/private_html..."
                                  mv -f ${OLDDIR_PUBLIC} ${NEWDIR}/private_html/
                                fi
                              }
                              done;
          }
          done;
}
done;

Rewrite users httpd.conf:
Code:
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
/usr/local/directadmin/dataskq d

You're now done! :) This way you:
  • Have the same folder names like you had in domain's public_html/private_html, and you see which domain is a subdomain created for
  • public_html/private_html would be available in SUB directory
  • .htaccess placed in domain's public_html/private_html would have no effect on subdomain
 
Thank you. However I still like this to be default in DirectAdmin. To avoid future problems, I will not do these custom changes. I will wait and hope DirectAdmin can change the default for subdomains.

Edit: However I like your path better (exept for the last "sub" wich I removed in my new suggestion: So my suggestion is that DirectAdmin in future versions make this the default path for subdomains: /home/username/domains/domain.com/subdomains
 
Last edited:
Last sub is a subdomain name, for example if you had ditto.mydomain.com, the full path to it would be /home/username/domains/mydomain.com/subdomains/ditto. Also, I forgot to add a removal script. The following needs to be added to /usr/local/directadmin/scripts/custom/subdomain_destroy_post.sh:
Code:
#!/bin/sh
rm -rf /home/$username/domains/$domain/subdomains/$subdomain
exit 0;
 
Martynas - thank you for show this way. But, like @ditto say - will be great when DA have this in standard. If I've application in Symfony2 framework I need set default web root to /home/account/domain/mydomain.com/public_html/web. When application should be on subdomain the more manual work (using htaccess or custom http config).

It will be a lot easier, when I can select path do domain/subdomain below /home/account/domains/mydomain.com/{whatever user want, default public_html} using web DA interface - not by DA hacks.

And - I think - this cut question about how to set other location to web root files, give solution to no need a hack DA files, will be accessible for not power user and make DA more flexible and more useful than now.
 
Last edited:
Hello,

This feature request has been in the versions system for quite some time.
http://www.directadmin.com/features.php?id=1007

However, it's not an easy fix as much of the way the templates are setup will break if we change variable structures for anyone who are using custom templates or the custom httpd config tool.
It might not be impossible, but if it's implemented, a completely backwards compatible setup would be required, which could be tricky.

John
 
If someone use custom templates or custom httpd config - should handle with this. If this feature request is in system from some time and number of view this topic is quite big - it is time to implement this?
Maybe use option in options.conf?
like variable_webroot = yes/no?

I see in the version system request is related to subdomain. From my point of view, if make changes:
1. it should give possibility to change webroot path for main domain too, not only for subdomain.
2. should be possible to make alias to all subdomain, *.mydomain.com => /home/user/domains/mydomain.com/.........
 
Last edited:
Back
Top