Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Creating Sub Domains

I have this site where a user selects a template for his site. I have to create a sub domain for that user on my site which will apply the selected template. My question is can I create a subdomain programmatically if yes then how? I am using cakephp. I want that users site will be accessible on some url after selecting a template.

like image 984
techie_28 Avatar asked Dec 05 '11 06:12

techie_28


People also ask

Can we create sub domain?

Rather than registering a new domain name, you can always create a subdomain using your existing domain name. A subdomain is an addon to your primary domain with its unique content. It is a separate part of your website that operates under the same primary domain name without you purchasing a new domain.

How to create a subdomain in PHP?

Traditionally, a subdomain in PHP is created manually from the cpanel. To do so, a developer has to enter information such as the name of the subdomain, the domain under which it has to be created. This process works completely fine if there is only one or a two sub domains to be made.

What is a subdomain?

A subdomain is a domain that is part of a larger domain. For instance if there is a website named www.suchagenericexample.com , then a sub domain of this website would look something like yeahtotally.suchagenericexample.com.

How to create subdomains on the fly using programming code?

This is where the importance of using programming code to create subdomains surfaces. In order to create subdomains on the fly, you can always add a snippet of code to your original code that will help you dynamically create subdomains. 1. Port 2082 must be open for your cPanel installation


1 Answers

Well, if you're running your own DNS servers, you can programmatically append new sub-domains to your DNS configuration files. I would probably not recommend that.

What most sites (like Wordpress.com and what not) most likely do is setup their DNS to point *.wordpress.com to their web server, then programmatically see if the sub-domain matches a valid account, then respond accordingly.

Most DNS servers support wildcard domains, such as:

*.yoursite.com.   3600 IN  MX 10 host1.yoursite.com.

so consult your manuals or help files for whatever DNS service you're using. Hope this helps!

like image 85
Mike Christensen Avatar answered Sep 24 '22 16:09

Mike Christensen