Setting up a blog on a subdomain

Here’s a little recipe that I want to share. Basically, if you’re a developer without much administrative practice you’re likely to spend an hour or two more than you normally should.

The goal is to setup a Wordpress blog on a subdomain, eg blog.domain.com, as an Apache virtual host through a secure shell.

Now you need to set up an Apache virtual host. In our case, we already had one running. Here’s the content of two vhost files:


 <VirtualHost *>
    ServerName www.domain.com
    ServerAlias domain domain.com
    DocumentRoot /path/to/your/app
</VirtualHost>

<VirtualHost *>
    ServerName blog.domain.com
    ServerAlias blog blog.domain.com
    DocumentRoot /var/www/wordpress
</VirtualHost>

Apparently the ServerAlias thing is really important otherwise you might for instance end up forwarding all requests to your site to the blog virtual host. Keep them in separate files in /etc/apache2/sites-available and a2ensite the blog one once done. Make sure that in your apache2.conf you have


NameVirtualHost *

which tells that you’re going to use name-based virtual hosting on all ports.

That should be all. Visit /wp-admin for WP to do it’s thing and you’re done.