Sunday, September 02, 2007

Setting up Subdomain in Apache2 and EditDNS

So, you want to setup a sub-domain? There's 2 things you need to do.

  • Configure Apache2
  • Add a Sub-domain to your EditDNS account (or your domain providers' control panel)
Configuring EditDNS
You should setup a subdomain on EditDNS first. Why, because it'll take time to propogate. That'll give you enough time to edit Apache's configuration files.

Before doing anything, make sure you can access your domain. If you can, then let's go ahead and create a sub-domain.

In the Record Name, type in
In the Type, select CNAME
Leave AUX and TTL alone
In the IP/Host, type in
Click Add
Repeat as needed

Here's my EditDNS Entry. I added blog, bugs, forum, learn, and wiki to my account.

Apache2 Configuration
Launch your favorite text editor and edit the default file as root. The file is in the /etc/apache2/sites-available.

sudo nano /etc/apache2/sites-available/default
kdesu kate /etc/apache2/sites-available/default

And append this to the file:
<VirtualHost *>
        DocumentRoot "/var/www/subdomain/kb/"
        ErrorLog /var/log/apache2/kb.log

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

  • The DocumentRoot should be pointed to the directory where you installed your site or script. And it should be enclosed in quotation marks. Don't forget that.
  • ServerName should have your subdomain
  • ServerAdmin and ErrorLog is optional.
  • The <Directory> should also be pointed to where you installed your site or script.
Here's mine:

And here's for my other subdomains. So you see, just edit the entry above to fit your configuration.

Now before you reload Apache2, you need to make sure that the default file is linked in /etc/apache2/sites-enabled. Otherwise, it just won't work.

If there's no linked file there, issue this command:
sudo a2ensite default

Once everything's done, go ahead and reload Apache:
sudo /etc/init.d/apache2 reload

Blogged with Flock