Bennett Hollstein

Web developer

[Ubuntu][Apache 2][Contabo VPS] Add Subdomain


in this tutorial I just wanted to show you how you can add a subdomain to a Ubuntu Sever with Apache 2 (but it will also work other Linux distros). I am using a Contabo VPS vServer with .de domain for this tutorial.

First, go to your domain settings. When you use Contabo, you will find it in the user webinterface at Now add a new DNS Entry to your domain with the name “[Subdomain].[Domain]”, you of course have to replace it so it looks like this:

The type for this is “A” and the data is the ip address of your server.

Now, the DNS entry is ready and you just have to set up the subdomain on your server.

For that, go into the terminal and make a new directory for the subdomain, for example /var/www/subdomain/

mkdir /var/www/subdomain

Now, edit the hosts file via

nano /etc/hosts

and add the following entry


Of course edit everything to your data, so it looks like this:


Please note, that between the IP and the domain there is a TAB but I couldn’t add it in this article.

Now create and edit the apache config for the subdomain

nano /etc/apache2/sites-available/

(replace the

And add the following:

<VirtualHost *:80>
 ServerAdmin mail@localhost
 DocumentRoot /var/www/subdomain
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined

(replace the

Next, activate the newly created subdomain conf via


Now you just have to restart the apache2 server

service apache2 restart

And your subdomain should be ready. Please note that it sometimes takes up to 15 minutes until the new DNS entry is registered, so don’t panic if it doesn’t work directly.

I hope you have working subdomain now,


Leave a Reply

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

* Die Checkbox für die Zustimmung zur Speicherung ist nach DSGVO zwingend.

Ich stimme zu.