Monthly Archives: January 2010

Creating Subdomains using command line

I have a server running Debian 5. I am serving multiple web applications using Apache2.

The setup I currently have is partially successful. I have a static IP. I also have a number of subdomains resolving to my IP address. These subdomains are:
– blog.ruslanverbelchuk.info
– admin.ruslanverbelchuk.info

If you have control over your DNS you can setup ‘wildcard hosting’, which means you can have a web server accept connections for any given subdomain. This can be enormously useful for community websites, or other hosting purposes.

Here is an example of the entry you’ll need to add:

*.ruslanverbelchuk.info IN A 192.168.1.1

Once you have your DNS entries setup you can alter your Apache virtual hosts to add an appropriate ServerAlias entry. This will allow Apache to treat a number of hostnames as equivilent.

Create host configuration files in /etc/apache2/sites-available:

nano /etc/apache2/sites-available/ruslanverbelchukinfo.info

A typical VirtualHost would look something like this:

<VirtualHost *:80>
     ServerAdmin ruslan.verbelchuk@gmail.com
     ServerName ruslanverbelchuk.info
     ServerAlias www.ruslanverbelchuk.info

     DocumentRoot /var/www/wordpress/public_html/
     ErrorLog   /var/www/wordpress/logs/error.log
     CustomLog  /var/www/wordpress/logs/access.log combined
</VirtualHost>

To allow this server to serve multiple other valid hostnames we simply add a ServerAlias setting:

<VirtualHost *:80>
     ServerAdmin ruslan.verbelchuk@gmail.com
     ServerName blog.ruslanverbelchuk.info
     ServerAlias blog.ruslanverbelchuk.info
     DocumentRoot /var/www/wordpress/public_html/
     ErrorLog   /var/www/wordpress/logs/error.log
     CustomLog  /var/www/wordpress/logs/access.log combined
</VirtualHost>

Create a symbolic link to those files in the sites-enabled directory:

a2ensite blog.ruslanverbelchukinfo.info
a2ensite ruslanverbelchukinfo.info

Activate new configuration:

/etc/init.d/apache2 reload

Check the relation between domain and IP address by ping
http://just-ping.com/index.php