Subdomain for each new user, is it posssible?


I am working on new project and I have idea to provide free sub-domain for each registered user.

I want users to have their unique sub-domain, also they should be able to change A or NS for their sub-domain, if possible. I don’t need any sub-directories for them, just a domain, so they could use it for their own needs for free. Example:

So question, is it even possible here in DigitalOcean? And if it is, could you give me some tips or tutorials how to set it up? It can be done by DigitalOcean API? I am new to this. Thanks!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I done it! Just what I wanted. Maybe this will be useful for someone, I was coding quickly, without any validations and so this more like an example, but it’s working, here is how I done it.

First of all, I use Laravel 5. But this will work for anyone who has Guzzle 4.0+ (doesn’t work on 6.0+).

In controller.

    public function addDomain(){

        $digitalOcean = new Client([
            'base_url' => '',
            'defaults' => [
                'auth' => [

        $request = $digitalOcean->post('domains', [
            'json' => [
                'name' => '',
                'ip_address' => ''

        $domain = $request->json();

        dd($domain); // just to see result.

Digital Ocean is BEST!! <3

Yes, managing A records for subdomains be done using the API. I set up a similar setup for a project of mine not long ago. Here is what I did.

  • I pointed my domain to ns1/
  • Via the control panel I added my domain in the DNS section and pointed the main domain and the www subdomain to my main droplet.
  • When a new user signed up my system would create a new droplet on my account for them and then use the API to create a subdomain record pointing to their new IP.
  • The API can then be used to either delete and recreate the subdomain or edit it.

This will allow the user to change their A record to point to any IP address.

Currently our DNS system does not support subdomain NS records so using this method would not allow your users to set up NS records to delegate their subdomain to another DNS server. If that is a requirement you would have to look into setting up nameservers using BIND or another DNS server and write the code to modify those records.

Documentation on managing records within a domain via the API.

This comment has been deleted