Sunday, August 24th, 2008 at 9:21 AM
I’ve been busy lately with lots of side projects (including the new theme surrounding this post), and one key tool that helps keep my work organized and sane is Subversion. A while back, I discovered that my web host of choice, MediaTemple offers two ways to host Subversion repos for your own usage alongside regular web hosting: you can make use of a single Apache webserver driven Subversion repository, or configure full-blown Subversion over secure SSH tunneling. Here’s how to get the latter up and running, complete with a hosted checkout of your work that auto-updates after your commit.
Enable SSH Access
By default, SSH remoting is disabled on MediaTemple accounts, requiring you to explicitly enable it in the Server Administrator control panel section for your primary domain:

Once there, set SSH on “Enabled”, and save your changes. MediaTemple’s easy-to-use configuration tool couldn’t make this step any simpler.

Connecting and Creating a Repository
Fire up Terminal in your Applications/Utilities folder under Mac OS X, or grab the latest version PuTTY under Windows, and connect to your MediaTemple host as serveradmin@yourdomain.com. For example, if your site were example.com, you would connect as follows:
ssh serveradmin@example.com@example.com
The domain “example.com” is in there twice, first because it’s part of your full username, and second to point SSH at the right server. (If your SSH client complains about not being able to connect, you can try replacing the first @ sign with its encoded version, “%25″.) Type “yes” to confirm adding example.com to your known_hosts, if asked, then enter your administrator password to finish logging in.
Enter the following commands to switch to your “data” directory (provided by MediaTemple), and create a basic repository for your code/information:
Change directory (cd) to your data directory:cd ../../data/
Create a “repos” directory to hold one or more repositories:
mkdir repos
Change directory to the folder you made in the previous step:
cd repos
Create a repository (replace “tests” with your desired repository name, using underscores for spaces). Letter case is important, so if you capitalize any part of the name now, you’ll have to capitalize it later when using it. The bit about “fsfs” is to use a specific Subversion database type recommended by MediaTemple — it’s the default type for newer versions of Subversion, but it’s best to put it just to be safe.
svnadmin create tests --fs-type fsfs
You can repeat this to create as many repositories as you wish inside the “repos” folder.
Log out of MediaTemple:
logout
Checking Out Your Repository
On your local computer (not on MediaTemple), decide where you want to keep your repositories. I recommend someplace easy to get to like /workingcopies/, but a repo can go anywhere you prefer. Check out a copy of the repo you just made:
svn checkout svn+ssh://serveradmin@example.com@example.com/home/1234/data/repos/tests /workingcopies/tests
Be sure to replace “1234″ with your four-digit MediaTemple server ID number that can be found in your Service Activation email.
To verify everything drop a simple file into your new repository folder at /workingcopies/tests, such as test.txt, and do:
svn add test.txt
svn commit -m "Adding test file."
Auto-updating MediaTemple
If you have some code stored in a repository that you’d like to automatically be made available to the world, such as a WordPress theme or web application, Subversion provides various “hooks” that can be run at times like pre-commit, post-commit, etc. Subversion hooks are nothing more than scripts which you define, and get run when the applicable action occurs. Here’s how to set up an automatically updating WordPress theme repository:
Connect to MediaTemple again, using the initial ssh command at the start of this tutorial, then change directory to where you want to use this repository on your MediaTemple server:
cd ../../domains/example.com/html/wp-content/themes
Check out a copy of your repository elsewhere on your server, using file:// instead of svn+ssh://
svn checkout file:///home/1234/data/repos/tests tests
Again, replace “1234″ with your server ID, and also replace “tests” with your repository name (in both places). Now you have a copy of that repository on your server. Edit the hook so it gets updated automatically when you commit changes:
cd ../../data/repos/tests/hooks
Make a copy of the post-commit hook example:
cp post-commit.tmpl post-commit
Use “pico” or “nano” to edit the post-commit script:
pico post-commit
Change the entire script (below #!/bin/sh) to:
svn update /home/1234/domains/example.com/html/wp-content/themes/tests
Exit pico, saving changes, with Control-X, Y, Enter.
Make your post-commit script executable:
chmod +x post-commit
Finally, log out of MediaTemple again:
logout
Now, after a commit, Subversion will automatically update the repo you have checked out on your server, and your changes should be reflected almost instantly.
There’s a lot more to using Subversion, so here are some hand-picked resources to keep you going:
Recommended
- Setting up Ubuntu Hardy
A good reference for setting up SSH keys, which ensures only you can log in remotely, and helps automate repetitive password entry - HOWTO: (gs) SVN multiple users
How to allow multiple users to access your repositories on MediaTemple - Version Control with Subversion
The free Subversion book/manual - Versions and Cornerstone
Two great Subversion applications for Mac - TortoiseSVN
The standard for Subversion under Windows
This entry was posted
on Sunday, August 24th, 2008 at 9:21 am and is filed under Tips.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, trackback from your own site, or
Stumble it!.
fmTuner: Last.fm for WordPress
ADB Mouse Conversion
iPod Super
Nice work on the site!
Dude, first of all thanks so much for this writeup. I will be using it at some time. But most of my congratulations go to your hard work on the site. It turned out beautifully and it looks sweet.
Cheers bro!
[...] right into your leafy-green development environment. And, after reading how to go about setting up Subversion on MediaTemple, your Mac web development paradise should be complete, ready to start developing all those killer [...]
[...] How to Set Up Multiple Subversion Repos on MediaTemple [...]
[...] public links >> repo How to Set Up Multiple Subversion Repos on MediaTemple Saved by Scrumtrelecent on Sun 28-9-2008 Eitan Isaacson: Let’s all do it right the first time [...]
Thanks!
I’ve been looking for this for awhile. Just one thing, the post-commit needs to have permission to execute. so I ran “chmod +x post-commit” to set permissions and everything works like a charm.
@Rodrigo: Thanks, nice catch! I’ve updated the post accordingly.