Installing/Setting up Subversion on Windows - with Apache

2008-09-04
Installing Subversion 1.5.2 on Windows 2000 Server already having Apache 2.2.9 installed.
Based on http://www.codeproject.com/KB/winsdk/SubversionApache.aspx

Did not get this to work properly! After going to http://localhost/svn/ in the browser in the end, I entered username and password, which it seemed to accept, but then displayed a 403 Forbidden instead of showing the repository root. Couldn't figure out why it did that.... So I set it up without Apache instead.

Install Subversion Download the latest version from http://subversion.tigris.org/ and copy content of zip files to somewhere, eg. under Program Files.
Add directory to environment variable "path"

Add path to the bin folder to the environment variable PATH.

I had to restart the computer for this to take effect.

Create repository root folder The next step is to create a directory which will be a root for all the repositories of our source control. Eg. create the directory c:\svnroot
Create a test repository

Create repositories in the svn root directories using the following commands:

svnadmin create c:\svnroot\test1

If you are told that MSVCP60.DLL is missing, you can download it from http://www.dll-files.com/dllindex/dll-files.shtml?msvcp60 and put it in your c:\windows\system32 folder.

Install Apache Download Apache from http://httpd.apache.org/ and install it - if you don't already have Apache installed. Minimum version 2.2.9 is required for the Subversion 1.5.2 that I'm using here.
Copy .so files When the installation is finished, go to the bin directory within the Subversion installation, find two files with extension *.so, and put them into the [Apache installation folder]/modules directory. The files are mod_authz_svn.so and mod_dav_svn.so.
Configure Apache

Add the following line in Apache config file, httpd.conf:

Include conf/extra/httpd-subversion.conf

Create the file conf/extra/httpd-subversion.conf and write the following in it:

LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so <Location /svn/> DAV svn # Specify the root for repositories # http://www.archivesat.com/CVS_developers_help/thread45479.htm : post which discuss why you need to specify /svn/ and not /svn SVNParentPath c:/svnroot/ # Allow list repositories SVNListParentPath on # Our access control policy (path and file where policy is written for each user) AuthzSVNAccessFile bin/apachesvnauth # Type of authentication AuthType Basic # Name of the authentication and the name of repository realm AuthName "Subversion Repository" # Name of the file with user passwords values AuthUserFile bin/apachesvnpasswd # Permit to log-in only for authorized users Require valid-user </Location>

Make sure that comments are on their own lines and not mixed with directives. Further explanation of the directives:

  • <Location /svn/> - if you type in your browser something like this: http://localhost:8080/svn/, then Apache will know how to find your root repository using SVNParentPath.
  • SVNParentPath c:/svnroot/ - specify the root for the repositories.
  • SVNListParentPath on - permit to see the list of repositories using http://localhost:8080/svn/.
  • AuthzSVNAccessFile bin/apachesvnauth - authentication file path where the policy is provided for each user. The file is stored in the bin sub-directory of Apache.
  • AuthType Basic - the type of authentication.
  • AuthName "Subversion repository" - the name of the authentication and the name of the repository realm.
  • AuthUserFile bin/apachesvnpasswd - the name of the file with user password values, stored in the bin subdirectory of the Apache installation.
  • Require valid-user - permit to log-in only for authorized users.

Building the password file

We use the AuthUserFile bin/apachesvnpasswd entry, which tells Apache to find the file with passwords in the bin sub-directory within the Apache installation directory. We need to build this file. Go to that directory using the command prompt and type the following command:

htpasswd.exe -c apachesvnpasswd user1

You will be prompted to enter the password for user user1, and the file apachesvnpasswd will be created in the bin sub-directory. In order to add another user, just type the same command without -c and provide the name of another user.

htpasswd.exe -c apachesvnpasswd user2

Note: only the users we created will be able to log into our repositories because we used the Require valid-user parameter.

Building the authentication file

The following block is an example of the authentication file:

[/] * = r [test1:/] user1 = rw user2 = [test2:/] user1 = r user2 = rw

Explanations

  • [/] * = r - gives access to everyone to read all the repositories
  • [test1:/] - gives read and write permissions to user1 for repository test1, and user2 can not read or write
  • [test2:/] - user1 can read from repository test2, and user2 has full access rights
Run Apache

Theoretically, we are at the stage when we can run Apache and test our Subversion. So start Apache, open the web browser and write something like this: http://localhost:8080/svn/.

If you don't get any errors, you will be prompted to type the username and password.

Provide the username you created and the password, and press OK. You will see the page with the title Collection of Repositories and the repository folders listed below.

  Remember to set up backup of your repositories using either dump or hotcopy command of svnadmin.
References