Subdomain on Digital Ocean Cloud in Simple Steps

Here are the steps to add a subdomain and get it working from a sub-folder in less than 20 minutes.

Step 1: Create an ‘A’ record for the subdomain.

To enable the subdomain we need to first add a subdomain host. Go to your DNS settings page and open the records where you have main domain DNS settings. Now add an ‘A’ record with subdomain in ‘Enter Name’ field (only add subdomain part. For example if you are going to create a subdomain then only enter blog and in the IP address field, enter the droplet IP.



DigitalOcean Control Panel


Step 2: Create a virtual host file for the subdomain.

– Now navigate to your /etc/apache2/sites-available folder.
– Create a file named You need to replace the subdomain and domain with yours.

– Paste the following code in the file. You can use nano command to create the file.


It will create a document and open it for editing. Replace the subdomain and domain in the code as needed.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/subdomain

    <Directory /var/www/subdomain>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
        Require all granted

    ErrorLog ${APACHELOGDIR}/error.log
    CustomLog ${APACHELOGDIR}/error.log/access.log combined



Step 3: Enable the subdomain.

We need to enable the subdomain before it can start showing up. Without this step the subdomain will show the main website.


We’ll also need to reload apache with new subdomain configuration.

service apache2 reload


Leave a Reply:

Your email address will not be published. Required fields are marked *