Skip to content

U. Setting up a subdomain

Bogdan Tudorache edited this page Apr 12, 2022 · 8 revisions

This chapter is not long delayed although it comes after a huge break, as all my other chapters, it comes from a need - the need for education and difficulty in finding the right resources online.

Funny enough this is also very simple if you know the right steps.

Prerequisites:

  • ubuntu server

  • apache2 webserver

  • godaddy account for the dns

A. What we want to achieve

We want to create a subdomain that points to a subdirectory of our webserver. We do not want to create a subdomain that points to a different IP, but if we wanted that we would have changed only the DNS settings.

B. Modifying the apache2 config

  1. We will create the subdomain directory first.

Go to /var/www/html and create a subdirectory : mkdir education

  1. a. We will modify the config file: /etc/apache2/sites-enabled/000-domain.io.conf

!! please be very careful when changing the settings. I suggest also creating a backup file

  1. b. Backup old file

cp /etc/apache2/sites-enabled/000-domain.io.conf /etc/apache2/sites-enabled/000-domain_BK.conf

  1. c. Update config by adding the subdomain first vi /etc/apache2/sites-enabled/000-domain.io.conf as per below:
<VirtualHost *:80>
    ServerName edu.berrynews.org
    DocumentRoot /var/www/html/edu
    <Directory /var/www/html/edu>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.edu.log
    CustomLog ${APACHE_LOG_DIR}/access.edu.log combined
</VirtualHost>


<VirtualHost *:80>
    ServerName berrynews.org
    DocumentRoot /var/www/html/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

  1. Copy the index.html file into the edu/ directory

  2. Restart apache2

    sudo systemctl restart apache2

Server side config is done. Now moving to GoDaddy config.

C. Subdomain in GoDaddy

I always have problems navigating into their website and it takes me at least 15 minutes to figure out where I made the changes; so this is me writing everything down.

  1. Log into GoDaddy In the top right corner, click on the dropdown arrow and choose "My Products"

Screenshot2022_04_12_175356

  1. Manage DNS In your product page, click on the 3 dots for the product you want to add the subdomain

image

  1. Add the subdomain

    Click on ADD;

    Name: edu (_exact name as subdirectory config_)
    Value: berrynews.org (_exact name of your domain_)

image

Now all that's left is to wait, they say at most 48H to fully replicate (believe them!)


                                            **Congrats, you're done!**

Conclusion

We have learned how to set up a subdomain that is pointing to the same IP as the original domain's IP.

We have also learned that this must be done in apache as well as in your DNS provider's page, and we must restart apache, always!

If you hit a problem or have feedback (which is highly welcomed) please feel free to get in touch, more details in the footer.