Published April 24, 2018 by

How to Create Sub Domains in Apache

In this tutorial, we demonstrate how to create a subdomain in Apache Web Server.

This is actually really easy. First, make sure your DNS is working. You can use A, AAAA or CNAME record as long as it points to your IP address.

Please check if it is working before you continue. You can check using ping subdomain.mydomain.com. If it is pointing to your IP address you're good.

Now create virtual hosts in Apache configuration file for Sub Domain.

# vim /etc/apache2/sites-enabled/000-default

Just adding this VirtualHost will do:

<VirtualHost *:80>
    ServerName subdomain.domain.com
    DocumentRoot /var/www/subdomain
</VirtualHost>

Now create /var/www/subdomain

# mkdir -p /var/www/subdomain

And put your subdomain files here.

Now Restart Apache

# service apache2 restart

Test it.

Go to a browser and hit subdomain.domain.com