SOLVED Hosting sub-domains but not main domain

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
Hi,

I have an unusual scenario coming up. I will be hosting a number of sub-domains, but not the main top/root domain. eg. I'll be hosting 'sub1.domain.com' and 'sub2.domain.com' and so on, but not 'domain.com'. I'll only be hosting web for these sub-domains and not mail. All I really need to be doing is creating entires in the httpd.conf. I do not need to be able to provide cPanel access for these.

So, short of creating an account for 'domain.com', setting it to external mail and pretending I am hosting it... is there a better way I could do this? Is there a way I can create a cPanel account for ownership of these sub-domains that is something other than 'domain.com'

Any tips appreciated.
 

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
Well, I don't really care if there is a cPanel account, but I need to create a number of sub1.domain.com, sub2.domain.com, and so on and point them to somewhere on my file system.

domain.com will not be on my server though, so creating a cpanel account for domain.com as a place to hold the sub-domains doesn't seem completely appropriate, though I'm guessing no real harm in it.

Are you suggesting creating individual cPanel accounts for sub1.domain.com, sub2.domain.com, and so on? That's not really practical as there will be 40 or 50 of them. Individual cpanel accounts seems a little over-kill, especially with account-based licensing/pricing coming!
 

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
I should say as well that all these sub-domains will be pointing to one of two Wordpress multi-site installs, so I do not need individual file-systems for each sub-domain.
I am also not worried about DNS... that is hosted elsewhere. All I really need to be able to do is create entires for httpd.conf that can point these subdomains to a location on the filesystem.
 

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
I guess another way to approach this, is that it doesn't really matter where/what cPanel account I use to host the Wordpress files. I just need a way to include a directory of hand-built .conf files into httpd.conf file that won't get nuked by updates and such. So, a way to add a custom include statement to httpd.conf that is officially supported by cPanel.
 

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
I guess another way to approach this, is that it doesn't really matter where/what cPanel account I use to host the Wordpress files. I just need a way to include a directory of hand-built .conf files into httpd.conf file that won't get nuked by updates and such. So, a way to add a custom include statement to httpd.conf that is officially supported by cPanel.
I think this is what I am looking for. I'll post back to confirm, in case anyone comes across this in the future.
Include Editor - Version 82 Documentation - cPanel Documentation
 

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
Moderator Note: This post was moved here from SOLVED - Apache Includes not getting included.

ahh.. ok, that sort of helps. I had thought it might be something like that, but it didn't quite work.

My ultimate goal is to be able to include virtual host containers of my own, not built with the normal cPanel tools. See this thread - New Thread - Hosting sub-domains but not main domain

I initially tried adding
Code:
# Load config files from the config directory "/home/serviceaccount/vhosts.d"
#
Include /home/serviceaccount/vhosts.d/*.conf
...and putting my small subdomain.conf file in /home/serviceaccount/vhosts.d/. That didn't work, but I see I would have been telling it to include an include.

I then tried adding
Code:
# test.sample.ca
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /home/serviceaccount/public_html
    ServerName test.sample.ca
    ErrorLog /home/serviceaccount/logs/httpd/sample.ca-error_log
    CustomLog /home/serviceaccount/logs/httpd/sample.ca-access_log common
</VirtualHost>
but that didn't seem to work either.

Ultimately, I'm going to have a Wordpress multisite install in the cpanel account for serviceaccount, that I need to point a bunch of sub-domains at, but the top-level domain for all these sub-domains is not on my server. I am not managing DNS or mail or anything. They just are creating cnames on their end to point the sub-domains to my IP address.

I thought I could leverage the apache include editor somehow to do this, but I am missing something.

I appreciate any guidance.
 
Last edited by a moderator:

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
DOH!!! a bit of a dummy moment here. I have figured out what I was doing wrong.

Putting the host container in the post include via the Apache Configuration editor does work... especially when you format it correctly. I was mistakenly copying something from an old server that only had one IP address. On this server, where I have several IP addresses, I had to start the vhost container with <VirtualHost 111.222.333.444:80> and not <VirtualHost *:80>

Sorry, rookie mistake ;-)

The concept works
 

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
I've also verified that just putting an include in the include does work and perhaps more convenient, though you have to run a configtest manually before restarting httpd when adding new virtual hosts.

For instance, using the WHM Apache Config editor, I can include this to the httpd.conf file
Code:
# Load config files from the config directory "/home/serviceaccount/vhosts.d"
#
Include /home/serviceaccount/vhosts.d/*.conf
and then any subdomain.conf files I put in that directory will get read into the httpd configuration when Apache is restarted. Note: it is a really good idea if doing something like this to run
Code:
# service httpd configtest
before restarting Apache. The WHM Apache Config editor does this for you when you use it. Otherwise, you're on your own.

I'll see if I can tie these subdomains into AutoSSL now and note that. I was using certbot and letsencrypt on the old server they are coming from, but that was not a cPanel server.
 

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
@cPanelMichael

The tricky part at this moment seems to be php-fpm. Am I correct in guessing that if I create a file at
Code:
/var/cpanel/userdata/serviceaccount/subdomain.serviceaccount.com.php-fpm.yaml
and then run
Code:
/usr/local/cpanel/scripts/php_fpm_config --rebuild --domain=subdomain.serviceaccount.com
that the plumbing will be done for me and the socket/pool built for php-fpm? I realize that I will have to look for the result and manually add that to my virtual host container.

Ps. I'm beginning to think it might be a lot easier just to 'fake' having the parent domain on my server with it's own account, even though that would not be entirely true.
 

verdon

Well-Known Member
Nov 1, 2003
911
10
168
59
Northern Ontario, Canada
cPanel Access Level
Root Administrator
In the end, it's a LOT easier to create a cpanel account for the top-level domain (even though I'm not hosting it) and then just proceed as normal from there. I set the name servers for the cpanel account to use the existing, set the mail exchange to remote, excluded the top-level from auto-ssl, and everything seems to be ok. It certainly a lot simpler than what I was trying to do.
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,749
2,206
363
cPanel Access Level
DataCenter Provider
Twitter
In the end, it's a LOT easier to create a cpanel account for the top-level domain (even though I'm not hosting it) and then just proceed as normal from there. I set the name servers for the cpanel account to use the existing, set the mail exchange to remote, excluded the top-level from auto-ssl, and everything seems to be ok. It certainly a lot simpler than what I was trying to do.
Hello @verdon,

Thanks for sharing the outcome and steps you used to accomplish this.

I concur with you that using the quoted method is preferred because the configuration files are setup automatically and any future changes to the configuration requirements won't require additional customization on your part.

Thank you.