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 apache 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](bla bla) file into the edu/ directory
  2. Restart apache2

sudo systemctl restart apache2

Contact:

🔗🌳 All-in-One

Clone this wiki locally