Automatically create a new subdomain on server

I have a Github project with three branches, master, staging and production.

When the staging code is merged with the production branch, a GitHub action runs and deploys my PHP website on my example.com. Good.

Now for QAs, I have set up a staging branch. Now what I want to do is that every time master is merged with staging, I want to create a new random subdomain for it like anything.example.com. The next time this workflow is performed, the new subdomain would be again randomly created. I would love to automate this using SSH commands.

My question is this workflow possible?

I have my hosting and domain on Hostinger.


Solution 1:

As subdomains must be registered in the DNS server, you will need to create the A or AAAA register in Hostinger first. I have not found that Hostinger offer an API for doing this (all the info ponints to registering the dns fields through the web pannel). If you really need this, maybe you should consider changing the DNS server to another.

Also instead of a subdomain, you can use a custom path in the url (like: my-domain.com/stagin/[random base-64 string]) or something like that, maybe.