How to create a subdomain in Apache?

Posted December 1, 2013 139.4k views
So I just created my Ubuntu server and everything is working fine. I set up the virtual host on my Apache following this tutorial ( My question is: how can I create a subdomain? I want that when you go to Apache goes to /var/www/subdomain/public_html (or something like that...).
1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
5 answers
Simply follow the steps in the article you cited, but replace with (but do not add the ServerAlias directive).
why not add a server alias?

First of all:

1- Configure the BIN9 at /etc/bind

If yout domain is, go to
and add the subdomain name

subdomainname IN A <= Repalce with IP

2- Go to Apache2 at /etc/apache2
Look for /etca/apache2/sitesavailable

Add new file named as:
and link it in apache2/sitesenabled


<VirtualHost *>
    DocumentRoot /var/www/domainname

    <Directory /var/www/domainname/>
        Options Indexes FollowSymLinks MultiViews +Includes
        AllowOverride None
        Order allow,deny
        allow from all

    ErrorLog ${APACHE_LOG_DIR}/error-logfile.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access-logfile.log combined


Dorival Cardozo
VirusCore AntiVirus Server manager

  • This contains various problems:

    1. Binding is not needed at all
    2. The Apache available site path is incorrect, it should be /etc/apache2/sites-available
    3. You should use the following command to enable an Apache site (instead of making symlink manually): sudo a2ensite {config filename}
    4. You should reload/restart Apache service afterwards.

@dorivalac did you mean private ip or public ip ?

Hello Support,

We don’t have bind server in our server. How can we configure the DNS Server to poin that CNAME.