Subdomain for each new user, is it posssible?

Posted May 27, 2015 13.3k views


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!

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.

Submit an Answer
3 answers

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.

  • Oh, alright. I will check it out. NS is optional, so A record would be totally fine.
    But if my system creates a new droplet on my account, it means I get additional monthly fee, right? And for each user, it would be very expensive. Or I miss something?

    Is it possible, that they can create sub-domains under my main droplet? And without additional expenses.

  • Is it possible, that they can create sub-domains under my main droplet? And without additional expenses.

    Absolutely. When you create an A record you can point it to any IP you like, a new droplet, your existing droplet, or a server outside DigitalOcean. The API endpoints that allow you to manage DNS records are not tied to droplet creation.

    If you simply wanted to point the user’s new subdomain to your existing droplet (and not allow them to edit the A record) you could set up a wildcard DNS record that would automatically point to your droplet. You could then have your scripts display your home page or a page telling a visitor that the subdomain they entered is available if a user is not already using that subdomain.

  • I want users to be able to create sub-domain (if it doesn’t exist already) and also allow them to point A record them selves. And make it so that they appear on my main droplet. That’s all. Sorry, if I didn’t sound clear, my English is not that good. :D

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.

“`use GuzzleHttp\Client;

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