How to create a subdomain instantly after user submitted a form like shopify?

671 views Asked by At

I am using cPanel api2+uapi to handle my domain to be very specific to create subdomain.

My subdomain is creating successfully there is no problem at all but its not getting activated instantly like how Shopify gives their users a subdomain instantly after user submits the store creation form.

I contacted my service provider about this issue they told me that cPanel users have to wait at least 5 minutes or even it would take 30/40 minutes to go live. So my question is:

  1. How is Shopify is creating subdomains instantly?
  2. If it's not possible in cPanel how can it be done? Or, in other words: how can I create a subdomain instantly using PHP?
1

There are 1 answers

3
Alex Howansky On BEST ANSWER

You can skip the cPanel API hits to create explicit subdomains and instead use a wildcard domain with multitenancy.

If your domain is foo.com then you can set up a DNS entry for *.foo.com that points to your app's IP(s). When your app takes an order, you write the new domain into the database and tell the customer their domain is whatever.foo.com which instantly resolves to your app. Your app can then look at the HOST header to determine what domain was requested, and act accordingly.