A. J. Roach
May 25, 2010
How To Set Up An SVN Repository In 7 Simple Steps
Make sure that svn is installed on your web host. Just ssh into your account and type
Lucky for me, my shared host already had svn installed at /usr/bin/svn. If you’re not so lucky, then you’ll need to install svn yourself. Depending on your system and your set up, there are multiple ways to do this. For this and all other svn questions, I’d recommend the svn red book. One of the finest examples of open source software documentation I’ve ever seen. Extremelyhelpful. Of course, if you’re on a shared host like me, then you probably won’t have the access you need in order to install svn. In that case, contact your system administrator and ask them to install svn for you.
Create your repository. Once svn is installed on your host, you can proceed with the repository set up. Just ssh into your server and create a repository wherever you’d like it. In my case I put my repository in my user directory. I would’ve preferred to have it in the root directory, but because it’s a shared host, I don’t have write access to anything outside of my user directory. To create the repository, issue the following command:
svnadmin create ~/myrepository
Create your SVN user: Now that your repository is successfully set up, you’ll need to create an svn user. Simply open the svnserve.conf file in the editor of your choice:
and add the following:
anon-access = none
auth-access = write
password-db = passwd
Now you’ll need to create a password file:
Add a line in that file for your user in the format =
exampleuser = examplepassword
Create a hierarchy for your repository: This step is optional. It’s not needed in order to get svn to work properly, but if you’re planning on keeping multiple projects under revision control, then it’s a good idea to get organized before you start importing those projects. In my case, I’ll be working on upgrading one of my sites from Drupal 5 to Drupal 6 soon (yes, I know… I’ve been putting that off too.), so I wanted a trunk for the Drupal 5 project and a trunk for the soon-to-be-upgraded Drupal 6 project. You can create directories in your repository in almost the same way you create them on your file system, using mkdir. You’ll need to use svn’s mkdir command though like so: NOTE: Relative paths don’t seem to work here. svn doesn’t seem to like ‘~’, so remember to start with the root directory (so it’ll look like ‘file:///root/rest/of/path…’. With three forward slashes.
svn mkdir file:///path to your repository/myrepository/d5
svn mkdir file:///path to your repository/myrepository/d6
Now you’re almost there. Next, you’ll need to import the files you want to keep under version control into your new repository. Do that with the svn import command.
svn import /path to your project/myD5project file:///path to your repository/myrepository/d5
svn import /path to your project/myD6project file:///path to your repository/myrepository/d6
Run the svn server as daemon:
Check out your repository onto your local machine: Back on your local machine, go to where you keep your nerd stuff. In my case it’s in ~/workspace. Then use the svn co command to check out a copy of your project.
svn co svn+ssh://username@hostname/path to repository/myrepository/d6
Go get a tasty beverage and rest comfortably in the knowledge that you’ll never have to scp another file again. Well, except for maybe the occasional mysqldump file…