
Saturday, 1st March 2008 at 12:30am
My situation: I was running www.allroundnews.co.uk fine on my shared host server, SH5 (thanks BEA Solutions ^^). Then I decided to switch to my VPS, Trinity, to run this blog. This blog is run from Trinity, but the rest of *.allroundnews.co.uk is still run from SH5. I realised that I was using up valuable space and bandwidth on SH5, when I had tonnes of both on Trinity. That's when I decided to run a virtual host for both of them. Here's how.
First, we have to fix the default Apache2 configuration, which isn't quite ready for vhosts yet. As root, edit the file /etc/apache2/sites-availiable/default. At the moment, mine and yours, if you haven't edited, looks like this, (well, I've changed the ServerAdmin, but that's about it.) We need to add the server name directive. That's just the URL that you want this vhost to be found at. I just had to add:
ServerName trinity.allroundnews.co.uk
That's fixed that. Since I'm running Trinity from a subdomain, that's all I need to add, but if you're expecting users to be able to use the www. prefix for your website, then you'll need to add a ServerAlias. If you're website is debianisawesome.com, you'd have something like the following:
ServerName debianisawesome.com
ServerAlias www.debianisawesome.com
Now that's fixed, we need to set up another VirtualHost for us to be using. In it, you need at least the ServerName and DocumentRoot directives. Remember, the ServerName is the URL Apache is "listening" for. The DocumentRoot is where it gets its files from. Try make this different from your default one, else it'll just get confusing. Here's what I've added to mine:
<VirtualHost *>
ServerName www.allroundnews.co.uk
ServerAlias allroundnews.co.uk *.allroundnews.co.uk
DocumentRoot /var/www-allroundnews/
</VirtualHost>
I went ahead and created /www-allroundnews/ too, and gave myself permissions.
My new config file can be found here.
All you need to do now is copy all your files from one server to your VPS. I did that by getting them all from SH5 using FTP, then uploading them all to Trinity using WinSCP. Any better way than that; comment, please!
Then, remember to point your old DNS records to your server, and you're good to go.