case
23Feb/092

How To – Setup a Subversion server on Windows

What is subversion

Subversion (svn) is a version control system initiated in 2000 by CollabNet. It is used to maintain current and historical versions of files such as source code, web pages documentations etc. Google code also provides free Subversion hosting but if you want your own private server continue reading to learn how to set up your own svn server

First: get the Subversion setup and run it to install Subversion.

Installing svnserve as a service
 
The simplest way to set up a server on Windows is to use svnserv which can be installed as a Windows service.
Run these commands in order to get the service up and running:
 

1
2
   mkdir c:\svn
   svnadmin create c:\svn\repos

Start the service:

1
2
   sc create svn binpath= "\"C:\program files\Subversion\bin\svnserve.exe\" --service -r C:\svn" displayname= "Subversion Server" depend= Tcpip start= auto
   net start svn

Note: There really are spaces after the = signs.
Check that it worked by checking out the repository:

1
   svn checkout svn://localhost/repos

Adding security

Edit C:\svn\repos\conf\svnserve.conf, uncomment these lines and change anon-access to none:

1
2
3
4
   anon-access = none
   auth-access = write
   password-db = passwd
   realm = My Subversion Repository

Now edit C:\svn\repos\conf\passwd and add a user name and password to the users section:

1
2
   [users]
   myusername = mypassword

Delete your first checkout and try to check out the repository again, this time you will have to supply a user name and a password.

Using WebDAV via Apache 2.2

Get and install XAMPP, install Apache and MySQL as a service. Unblock ports as needed when the installation is finishing up.

As we are installing Apache 2.2 so we need builds of the Subversion Apache modules which are compatible with Apache 2.2 which are available here.

XAMPP has a prebuilt mod_dav_svn and mod_authz_svn - they don't work, replace them with the Apache 2.2 built ones which you have just downloaded, the zip file contains a complete build of Subversion but we only need the two Apache module files. The files to replace are mod_dav_svn and mod_authz_svn in c:\xampp\apache\modules.

Edit C:\xampp\apache\conf\httpd.conf and add:

1
   Include conf/extra/httpd-subversion.conf

Put this in that file:

1
2
3
4
5
6
   LoadModule authz_svn_module modules/mod_authz_svn.so
   LoadModule dav_svn_module modules/mod_dav_svn.so
   <location /svn/repos>
     DAV svn
     SVNPath c:/svn/repos
   </location>

Stop and start the Apache service, either using the command line or the XAMPP Control Panel Application. Fire up a web browser and go to http://localhost/svn/repos.

Adding Security

In httpd-subversion.conf, add this to the Location directive:

1
2
3
4
   AuthType Basic
   AuthName "Subversion Repository"
   AuthUserFile c:/svn/passwords
   Require valid-user

Now create a password file and add a user, note: xamp htpasswd doesn't like drive letters.

1
2
3
   C:\svn>c:\xampp\apache\bin\htpasswd -cb \svn\passwords myusername mypassword
   Automatically using MD5 format.
   Adding password for user myusername

Then restart Apache again. You will now need to use the user name and password to access your repository.

If you're not familliar with the svn command line or you find it to hard to use, just download TortoiseSVN. You'll love it.