Solved Username as a prefix for the parent domain name when a new user register

hostmost

Verified User
Joined
May 31, 2022
Messages
41
Hello guys!

I have an important question that I hope anybody can help me with.

Before asking this question, I've been trying to research for an extensive amount of time around this forum and other places as well, with no luck.

What I'm trying to do is the following thing.
When anybody registers, I want them to choose the ending name for the domain name that I'll have pre-set already.
For instance, I have a domain name, example.com, and I want users to have access somehow to that domain with their username, so it'll look like this: username.example.com

Is there a way to do something like this? I was thinking of making it work on the server level as a subdomain somehow, but I'm not sure how to implement it yet.

It'll be nice to hear some of your ideas, guys. I'm sure It'll be helpful for others too.
 
You can use user_create_post.sh and add there line add them domain pointer like |username|.example.com
exact syntax check on DA wiki
 
(This is just my idea )
if you just want your client only use your provide domain only.

Create new username with your provide "username.domain.com".

note: if you already have "domain.com" in yoor server, you need to disable domain owner check option for create sub.domain from other user.

then you need to disable domain management option about create/edit/delete on that user.




p.s. Don't add subdomain in your same account for that user. because they can read your all relate files by some trick.
 
Thank you, guys, for your ideas, but I started thinking a bit more, and here is my question. I want users to be able to use this domain name for their projects, even if they didn't assign any domain.

In other words, I want every user to be able to use the unique domain name provided by the server.

I also know that domain management on the server level is performed with the httpd config file.
Is there a way to do something like this?

For example, if I register the domain name freeexample.com, so each user has access to this domain this way: |username|.freeexample.com and can use it any time for projects.

Any ideas on how and where to begin?

Thank you!
 
Last edited:
In other words, I want every user to be able to use the unique domain name provided by the server.
Shortly said, do you want a kind of no-ip.org or dyndns.com domain kindlike script?

Search with Google for "dyndns directadmin" and you will see some threads on the forums here, even with a script on how to accomplish that.
Here for example:
 
Shortly said, do you want a kind of no-ip.org or dyndns.com domain kindlike script?

Search with Google for "dyndns directadmin" and you will see some threads on the forums here, even with a script on how to accomplish that.
Here for example:

Hello Richard!

Thank you for your reply. I read everything I could find, and I understand that the solution you are talking about is proxying the domains via dyndns. This is not really what I need.

I'm trying to give all the new users who register on the host an option to use a domain name offered from the server by default, even if they haven't assigned their domain yet.

The purpose of that domain is to be a test domain for user's projects and have all the functionality as a regular assigned domain.
 
and I understand that the solution you are talking about is proxying the domains via dyndns.
No it's not proxying anything. For the DNS part it does exactly what you are asking for. ;)

I'm trying to give all the new users who register on the host an option to use a domain name offered from the server by default, even if they haven't assigned their domain yet.
You mean subdomain according to your explanation earlier. This is exactly what Dyndns or no-ip.org do DNS wise. So you are looking for that kind of setup which is what the threads are about which I'm pointing to. They use a kindlike script, to do the same locally.
Then you are half way there. I didn't say I could link you to a full working version of what you want. ;)

The user registers and then gets a name like for example user234.domain.com and another user registers and gets somebody.domain.com where domain.com is in fact owned by you, they only use the subdomains and can have their own websites on there.
The trick is only to keep those subdomains seperated accesswise.

If you have that DNS part, you don't proxy anything, it can work directly on your own server where you have domain.com running which you want to use for that purpose. And with a correct script you can add webspace to the subdomains.

This link is coming from one of the threads I mentioned and as far as I can see, does what you want.

Again, this script is most likely also not 100% anymore, but it's contains almost everything you need. So you could change/update that to your needs. Fact is the tricks you are looking for are in there.

You asked how/where to begin, that's the answer to it.
 
Thank you all for the help, guys.

Finally, I was able to manage it all. Nothing suggested above was used.
Instead, having a properly configured custom httpd.conf and its related config files, especially subdomains, is everything needed.
I resolved it by offering subdomains, as I wanted, using the billing system configurations (WHMCS).

Best practices:
Don't use your root domain as an option to offer it as a free subdomain. Instead, get another domain, assign it as Admin in your DirectAdmin panel, and make sure DNS is set correctly.
If using your main domain, you'll mess up your DNS records by starting to have lots of extra records from each subdomain created.

I'll mark it as resolved.

Cheers!
 
Instead, having a properly configured custom httpd.conf and its related config files, especially subdomains, is everything needed.
Care to share how? :)

Also did you think of putting the custom configs for httpd in the custom/ap2/conf or related directory's so the httpd.conf (and maybe other customized configs) will not get overwritten anymore on an apache update?

Good job by the way.
 
Care to share how? :)

Well, each setup is unique and depends on the infrastructure and system's configuration.

Here, I'll share my virtual_host_sub.conf file

|CUSTOM1|
|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html|
|?REALDOCROOT=`HOME`/domains/`DOMAIN`/public_html|

|?HOST_DOMAIN=`DOMAIN`|
|*if HOST_POINTER|
|?HOST_DOMAIN=`HOST_POINTER`|
|*endif|

|?OBDP1=|
|*if PHP1_RELEASE!="0"|
|?OBDP1=:/usr/local/php`PHP1_RELEASE`/bin/lsphp`PHP1_RELEASE`|
|*endif|
|?OBDP2=|
|*if PHP2_RELEASE!="0"|
|?OBDP2=:/usr/local/php`PHP2_RELEASE`/bin/lsphp`PHP2_RELEASE`|
|*endif|

|?OPEN_BASEDIR_PATH=`HOME`/:/tmp:/var/tmp:/opt/alt/php`PHP1_RELEASE`/usr/share/pear/:/dev/urandom:/usr/local/lib/php/`OBDP1``OBDP2`|

|?FASTCGI_OPENBASEDIR=|
|*if OPEN_BASEDIR_ENABLED="ON"|
|?FASTCGI_OPENBASEDIR=-d open_basedir="`OPEN_BASEDIR_PATH`"|
|*endif|

|?PHP_MAIL_LOG=|
|?CLI_PHP_MAIL_LOG=|
|*if PHP_MAIL_LOG_ENABLED="1"|
|?PHP_MAIL_LOG=-d mail.log="`PHP_MAIL_LOG_DIR`/php-mail.log"|
|?CLI_PHP_MAIL_LOG=php_admin_value mail.log `PHP_MAIL_LOG_DIR`/php-mail.log|
|*endif|

|?PHP_EMAIL=`USER`@`DOMAIN`|
|?FASTCGI_SENDMAIL_FROM=-d sendmail_from="`PHP_EMAIL`"|

|?ALLOW_OVERRIDE=AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,IncludesNOEXEC,MultiViews,SymLinksIfOwnerMatch,FollowSymLinks,None|
|?COMBINED_LOG=combined|

<VirtualHost |IP|:|PORT_80| |MULTI_IP|>
|CUSTOM|
|?SDOCROOT=`DOCROOT`/`SUB`|
|?CGI=ScriptAlias /cgi-bin/ `SDOCROOT`/cgi-bin/|
ServerName www.|SUB|.|HOST_DOMAIN|
ServerAlias www.|SUB|.|HOST_DOMAIN| |SUB|.|HOST_DOMAIN| |SERVER_ALIASES|
ServerAdmin |ADMIN|
DocumentRoot |SDOCROOT|
|CGI|

|USECANONICALNAME|

|FORCE_SSL_REDIRECT|
|UNIT_PROXY|

<IfModule !mod_ruid2.c>
SuexecUserGroup |USER| |GROUP|
</IfModule>
|*if HAVE_RUID2="1"|
<IfModule mod_ruid2.c>
RMode config
RUidGid |USER| |GROUP|
#RGroups apache |SECURE_ACCESS_GROUP|
RGroups @none
</IfModule>
|*endif|
|*if RUID2_AND_MOD_SECURITY="1"|
<IfModule mod_security2.c>
SecAuditLogStorageDir |MODSEC_AUDIT_DIR|/|USER|
</IfModule>
|*endif|

CustomLog |APACHELOGDIR|/|DOMAIN|.|SUB|.bytes bytes
CustomLog |APACHELOGDIR|/|DOMAIN|.|SUB|.log |COMBINED_LOG|
ErrorLog |APACHELOGDIR|/|DOMAIN|.|SUB|.error.log

|*if SUSPENDED_REASON|
<IfModule mod_env.c>
SetEnv reason |SUSPENDED_REASON|
</IfModule>
|*endif|

|*if HAVE_PHP1_FPM_OLD="1"|
#Make sure you're running Apache 2.4.10 or newer.
|*endif|

|*if HAVE_PHP2_FPM_OLD="1"|
#Make sure you're running Apache 2.4.10 or newer.
|*endif|
|CUSTOM2|
<Directory |SDOCROOT|>
|CUSTOM3|
|*if CGI=""|
|ALLOW_OVERRIDE|
Options -ExecCGI -Includes +IncludesNOEXEC
|*endif|
|*if HAVE_PHP1_FPM="1"|
<FilesMatch "\.(inc|php|phtml|phps|php|PHP1_RELEASE|)$">
<If "-f %{REQUEST_FILENAME}">
#ProxyErrorOverride on
AddHandler "proxy:unix:/usr/local/php|PHP1_RELEASE|/sockets/|USER|.sock|fcgi://localhost" .inc .php .phtml .php|PHP1_RELEASE|
</If>
</FilesMatch>
|*endif|
|*if HAVE_PHP2_FPM="1"|
<FilesMatch "\.(inc|php|phtml|phps|php|PHP2_RELEASE|)$">
<If "-f %{REQUEST_FILENAME}">
#ProxyErrorOverride on
AddHandler "proxy:unix:/usr/local/php|PHP2_RELEASE|/sockets/|USER|.sock|fcgi://localhost" .php|PHP2_RELEASE|
</If>
</FilesMatch>
|*endif|

|*if HAVE_PHP1_FCGI="1"|
<IfModule mod_fcgid.c>
FCGIWrapper '/usr/local/safe-bin/fcgid|PHP1_RELEASE|.sh /usr/local/directadmin/data/users/|USER|/php/|DOMAIN|.ini |JAIL_TRUE_FALSE| |FASTCGI_SENDMAIL_FROM| |FASTCGI_OPENBASEDIR||FASTCGI_PHP_SETTINGS| |PHP_MAIL_LOG|' .php
<FilesMatch "\.php$">
SetHandler fcgid-script
Options +ExecCGI
</FilesMatch>
</IfModule>
|*endif|
|*if HAVE_PHP2_FCGI="1"|
<IfModule mod_fcgid.c>
FCGIWrapper '/usr/local/safe-bin/fcgid|PHP2_RELEASE|.sh /usr/local/directadmin/data/users/|USER|/php/|DOMAIN|.ini |JAIL_TRUE_FALSE| |FASTCGI_SENDMAIL_FROM| |FASTCGI_OPENBASEDIR||FASTCGI_PHP_SETTINGS| |PHP_MAIL_LOG|' .php|PHP2_RELEASE|
<FilesMatch "\.php|PHP2_RELEASE|$">
SetHandler fcgid-script
Options +ExecCGI
</FilesMatch>
</IfModule>
|*endif|
|IF_MODULE_LITESPEED_OPEN|
|*if HAVE_SAFE_MODE="1"|
php_admin_flag safe_mode |SAFE_MODE|
|*endif|
|*if CLI="1"|
php_admin_flag engine |PHP|
php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f |PHP_EMAIL|'
php_admin_value session.save_path=/home/|USER|/domains/|DOMAIN|/tmp
|CLI_PHP_MAIL_LOG|
|CLI_PHP_SETTINGS|
|*endif|
|*if OPEN_BASEDIR="ON"|
php_admin_value open_basedir |OPEN_BASEDIR_PATH|
|*endif|
|IF_MODULE_LITESPEED_CLOSE|
|*if HAVE_PHP1_CLI="1"|
<FilesMatch "\.php$">
AddHandler application/x-httpd-php|LSPHP1_RELEASE| .php
</FilesMatch>
|*endif|
|*if HAVE_PHP2_CLI="1"|
<FilesMatch "\.php|PHP2_RELEASE|$">
AddHandler application/x-httpd-php|LSPHP2_RELEASE| .php|PHP2_RELEASE|
</FilesMatch>
|*endif|
|*if SUPHP="1"|
suPHP_Engine |PHP|
suPHP_UserGroup |USER| |GROUP|
|*endif|
|*if HAVE_PHP1_SUPHP="1"|
<FilesMatch "\.php$">
AddHandler x-httpd-php|PHP1_RELEASE| .php
</FilesMatch>
|*endif|
|*if HAVE_PHP2_SUPHP="1"|
<FilesMatch \.php|PHP2_RELEASE|$>
AddHandler x-httpd-php|PHP2_RELEASE| .php|PHP2_RELEASE|
</FilesMatch>
|*endif|
</Directory>
|MOD_SECURITY_RULES|

|*if USE_HOSTNAME_FOR_ALIAS="1"|
RewriteEngine on
RewriteOptions inherit
|*endif|

|*if WEBSERVER="litespeed"|
<IfModule Litespeed>
CacheRoot lscache
|BUBBLE_WRAP|
</IfModule>
|*endif|

|HANDLERS|
|MIMETYPES|
|HOTLINK_PROTECTION|
|CUSTOM4|
</VirtualHost>
In case anybody needs an example of the configuration. Don't forget about the *_sub_secure.conf file as well. I won't share it here, you'll be able to figure it out by the example above.

Also did you think of putting the custom configs for httpd in the custom/ap2/conf or related directory's so the httpd.conf (and maybe other customized configs) will not get overwritten anymore on an apache update?
Custom files are going to the: date/templates/custom
Don't forget to rewrite configs when done.

Good job by the way.
Thank you!
You are very welcome to try the web hosting out and enjoy the free plan along with the free subdomain ;)

Cheers!
 
I was also looking to do something like this, as it's how SiteGround's temporary domain structure works and I'm having issues with WordPress installations not working using the ~userdir link.
 
Back
Top