Back from holidays

After great holidays on the Canarian Islands I'm now back in front of the trusty computer. The trip was super, resulting in some much needed extra energy and motivation for ... well, lots of things, really :) The first bigger thing I've done after coming back is moving from a server I have at home to my VPS. The reason is rather simple, really: the connection here is simply not stable enough for me to have my company site running over it (it's a combination of crappy router plus wrong linux install, I think).

Before moving stuff I thought it might take a bit of effort getting things working without problems but it turned out I had no reason to worry. A combination of git and gitosis made the basic transfer easy and the rest was handled with a database dump + import and a new virtualhost for Apache. Replicating the install looked like this:

Step 1 - setup local repo

Make sure the site you're moving is in a git working repo. Skip this if you're in a working git repo, otherwise just do something like

git init
git add --all
git commit -am "setting up git repo for myproject"

Your repo is now ready to move - need a place to move it to, though.

Step 2 - add group to gitosis

If you've not already setup gitosis on your server (local or remote) have a read on the blog. When gitosis is running, you need to modify your gitosis.conf to add a new group for the site you want to move (unless you've got one group for everything, which I wouldn't recommend though). In your gitosis.conf, add

[group mygroup]
writable = myprojectname
members = user1 user2 user3@host

Save and move on.

Step 3 - add remote repo to your local working directory

If like me your gitosis daemon is running on a remote server, you need to do something like

git remote add remote_repo_name ssh://git@host/myproject.git

If gitosis is running locally, you can do away with the ssh protocol bit

Step 4 - push

Time to do the actual copy. Do

git push remote_repo_name master

Your repo is now copied to gitosis.

Step 5 - clone

Check out a working copy by cloning the site to where you need it - i.e. do

cd /var/www
git clone /path/to/gitosis/repos mysite

If your new site is on the same server as the gitosis server, that is. Otherwise, use the ssh protocol for the path.

Step 6 - dump database

PL PHP is running on MySQL - hence, dumping the database and copying it across to the new site can be done by

mysqldump -u user -p database > dump.sql && scp dump.sql user@host:~/

Step 7 - setup proper user

Setup a user with access to the database using the same details as on the current site - a create 'user'@'localhost' will probably suffice.

Step 8 - import database

Create the database, then import using your sql

mysql> create database mydb default charset utf8;


bash:~/$ mysql -u user -p -D mydb < dump.sql

And done

Step 9 - create new virtualhost

Get Apache to serve up the site by creating a new virtualhost file. Then check your Apache config with apache2ctl configtest - if it's working fine, then restart apache.

Step 10 - change DNS records

Last thing is to switch DNS records so your domain points to the new IP.

That's it - 10 steps and PL PHP was migrated to a different server with the added benefit of having a repo copy added to my gitosis daemon. If you skip the gitosis bit then you can truncate step 1-5 - just clone the repo straight away.

On the other hand, if your site is bigger than PL PHP, you probably want to add some extra steps, such as having your current site proxy the new site, so that no traffic will hit the current site (and thus the current database). An alternative to this would be to setup the new site to use the current database and only migrate the database when you're sure DNS records have been changed (i.e. when you no longer see hits on the old IP).

With this out of my mind, I can focus on other interesting stuff, such as the Typo3 book review I'll be doing (expect that in a little over a week) and an interesting project focusing on the craft community which I'm doing with my fiancee :)