How to create a sub domain?

October 28, 2019 474 views
Applications Apache DigitalOcean DNS Control Panels Configuration Management

I added CNAME and configured virtual host perfectly, but sub domain not working, please help me anyone…

1 Answer


If this is going to be a separate website, I would recommend adding an A record for your subdomain name rather than CNAME. That way if the A record for your main domain changes, it would not affect your subdomain.

Also, note that it could take between 1 and 72 hours for the DNS cache to clear over the Globe before you could see your new DNS records.

If you are still experiencing the issue, you could share your Vhost here and I could try to advise you further.


  • I am also used A record but no use, this is my vhost

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory /var/www/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


    • Hello,

      It looks like that you are using CloudFlare’s Nameservers, this means that you need to create the A record for your domain name via your CloudFlare DNS zone.

      This would fix your issue.


      • Note that after the DNS change at CloudFlare’s end, you might have to wait between 1 and 72 hours for the DNS cache to clear over the Globe.

      • Yes, i am used cloudflare, now subdomain is working but when i am open it shows content, what’s wrong?

        • Hi @nanirules15

          Well done! Now the DNS for your subdomain name is correct.

          Now you need to make sure that you have your content at /var/www/ and also that the files in that folder have the correct ownership:

          sudo chown -R www-data:www-data /var/www/

          If this still does not work, you need to check your error log at:

          tail -100 /var/log/apache2/error.log


          • Thank you for continue support!!!
            i used below command

            sudo chown -R www-data:www-data /var/www/

            but still no use, shows content
            can i give you “error.log” file?

          • Hi @nanirules15

            Yes, feel free to share the error here. Just make sure to remove any sensitive information like your IP from there.


          • i am trying to create subdomain for another domain it’s working 100% without any problem, that domain also hosted in digitalocean, but i can’t use cloudflare for that one

          • Hi @nanirules15

            The error that you are seeing in the logs is saying that either your /var/www/html/tools/ directory is empty or that there is no index file like index.html, index.php or similar.

            Once you add your website files along with the index file it would work as normal.


Have another answer? Share your knowledge.