HOWTO: Subversion for Windows with Apache server

1. Introduction
2. Installation
2.1. Setting up the OS
2.2. Installing Subversion
2.3. Installing Apache 2.2
3. Configuration
3.1. Configuring Subversion
3.2. Configuring Apache 2.2 server
4. Backup
4.1. What to back up?
4.2. Creating a repository dump
5. Upgrade
5.1. Upgrading Apache 2.2 server
5.2. Upgrading Subversion
1. Introduction
The Subversion for Windows HOWTO describes from a beginner’s perspective, how to install the Subversion server with Apache on a Windows system, and get it running. This how to describes how to use the Apache 2.2 server as the network server component of the Subversion.
This guide is verified on Windows XP, Windows Server 2000 / 2003 and Windows 7. The same point is valid, if you choose to use Apache 2.0 out of any reason – i do not know at the moment.
I will describe all topics that include the installation, basic configuration and setting up backup. It will provide working examples of configuration, ready for you to modify and use.
2. Installation
This chapter describes the process of installation, beginning with the OS installation, continuing with Subversion server installation and ending with Apache 2.2 server installation. You need to install and configure Subversion and Apache 2.2 server as local Administrator on your system.
2.1. Setting up the OS
Since this isn’t a Windows HOWTO, this chapter will be rather short, and answer a few simple questions that I had before I began. The two OS related questions that I was asking myself before starting with the OS installation were:
- Does the Subversion server work with Windows 7 and all the patches?
- Does the server work on DHCP enabled interface? [some apps don't, you know]
The answer is YES. Install the Windows 7 and all the latest service packs and patches however don’t forget to open the HTTP (80)/ HTTPS(443) (or whatever you setup in your Apache web server) port in firewall to access SVN.
2.2. Installing Subversion
You can download latest release of subversion following this URL:
http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91
This documentation describes “Subversion version 1.5.6″, (Setup-Subversion-1.5.6.msi).
Follow setup wizard instructions to complete Subversion installation. The default directory is “C:\Program Files\Subversion” and below is a list of directories the installation creates:
| C:\Program Files\Subversion\bin | Contains all the binaries like svn.exe, svnadmin.exe and svnlook.exe. And Contains the Apache 2.2 plug-in modules mod_authz_svn.so and mod_dav_svn.so . | |
| C:\Program Files\Subversion\iconv | ||
| C:\Program Files\Subversion\share | ||
| C:\Program Files\Subversion\licences |
The C:\Program Files\Subversion\bin is added to the path.
And that’s about all there is to the installation.
2.3. Installing Apache 2.2
The Apache 2.2 server for Windows installation package can be downloaded from the Apache.org server, at the following URL:
http://httpd.apache.org/download.cgi
This article describes this “apache_2.2.14-win32-x86-openssl-0.9.8k.msi” version of Apache.
Follow setup wizard instructions to install Apache. During installation process you need to:
- Select the Apache binding
- Enter your domain name
- Server name
- Administrator’s e-mail address and
- The port the server will be listening on. You can override default values. For dedicated a subversion server, I suggest you leave it running on port 80. You can change this port later.
- You can select typical or custom install. Selecting typical install lets you choose the destination directory.
At the end of installation process, installer may prompt to restart your server. I recommend you to restart server to finish installation.
3. Configuration
We will discuss to configure the Subversion system and Apache Web Server to make it available over the network/ internet.
3.1. Configuring Subversion
The Subversion stores the content in repositories. You need at least one repository to store all your data into, or may setup multiple repositories, one for each project. This HOWTO will assume multiple repositories are used. We will call these projects project1 and project2.
Let’s create a directory for all our projects, and then a subdirectory for each of the projects, e.g.:
C:\Repositories\project1
C:\Repositories\project2
These are just directories to hold our repositories, now need to create the repositories themselves, using the “svnadmin” utility:
svnadmin create C:\Repositories\project1
svnadmin create C:\Repositories\project2
Note: Make sure to create all repositories on your local disks [FiberChannel is treated as a local disk]. Failing to do so, may result in repository corruption.
Each repository is stored in a Berkeley DB database, which can be configured in many different ways, but the default configuration works, and for a beginner, I found no reason to change anything.
To make repositories available to your development teams, you need to setup Apache Web Server.
3.2. Configuring Apache 2.2 server
As the Apache server will only be a front end for the Subversion system. I suggest storing all Subversion specific files in separate directory.
C:\etc
Note: The Apache server require writing all the directories using forward slash as the separator e.g. “C:/Program Files/Apache Software foundation/Apache2.2″.
Step 1:
Copy the files mod_authz_svn.so and mod_dav_svn.so from “C:\Program Files\Subversion\httpd” into “C:\Program Files\Apache Software foundation\Apache2.2\modules”.
Step 2:
Modify the “C:\Program Files\Apache Software foundation\Apache2.2\conf\httpd.conf” file:
- Add the modules to the Apache server
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
-
Add the Access lines to the <Directory> sections, to protect your system.
Make sure you have the rights to change the file!
<Directory />Options FollowSymLinksAllowOverride NoneOrder Allow,DenyAllow from 10.0.1</Directory><Directory "C:/Program Files/Apache Software foundation/Apache2.2/htdocs">## Possible values for the Options directive are "None", "All",# or any combination of:# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews## Note that "MultiViews" must be named *explicitly* --- "Options All"# doesn't give it to you.## The Options directive is both complicated and important. Please see# http://httpd.apache.org/docs/2.2/mod/core.html#options# for more information.#Options Indexes FollowSymLinks## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:# Options FileInfo AuthConfig Limit#AllowOverride None## Controls who can get stuff from this server.#Order allow,denyAllow from 10.0.1</Directory>
This allows access from all computers in the address range 10.0.1.1 – 10.0.1.254 .
- At the end of the file, include a Subversion configuration file. We will create this file in one of the next steps.
Include c:/etc/subversion.conf
- Place the “subversion.conf” file in the before mentioned etc directory.
Step 3:
To restrict anonymous access to repositories and protect projects/ repositories or setup permissions for specific users on a projects/ repositories, we need to create a password file for authentication.
Subversion should only accessible to authenticated users, e.g. you need to provide credentials to access Subversion. You need to create developer accounts with passwords.
Let us name our developers Harry and Sally. Since we have two projects, we’ll have a somewhat bigger development department, adding Ross and Rachel to our list of employees.
cd C:\Program Files\Apache Software Foundation\Apache2.2\bin
htpasswd -cm C:\etc\svn-auth-file harry
C:\Program Files\Apache Software Foundation\Apache2.2\bin>htpasswd -cm C:\etc\svn-auth-file harry
New password: *****
Re-type new password: *****
Adding password for user harry
C:\Program Files\Apache Software Foundation\Apache2.2\bin>htpasswd -m C:\etc\svn-auth-file sally
New password: *******
Re-type new password: *******
Adding password for user sally
C:\Program Files\Apache Software Foundation\Apache2.2\bin>htpasswd -m C:\etc\svn-auth-file ross
New password: *****
Re-type new password: *****
Adding password for user ross
C:\Program Files\Apache Software Foundation\Apache2.2\bin>htpasswd -m C:\etc\svn-auth-file rachel
New password: *****
Re-type new password: *****
Adding password for user rachel
When using the command for the first time, add the -c option. This creates the file named “C:\etc\svn-auth-file”. The -m option instructs the htpasswd utility to use MD5 algorithm to encrypt the passwords.
Step 4:
Now we can authenticate our users, we must configure the access rights to our repositories. To setup access rights, we need to create another file in our etc directory.
#
# specify groups here
#
[groups]
team1 = ross, rachel
#
# team1 group has a read/write access to project1 repository
# all subdirectories
# all others have read access only
#
[project1:/]
@team1 = rw
* = r
#
# project2 repository, only harry and sally have read-write access to project2
#
[project2:/]
harry = rw
sally = rw
* = r
#
# ross is helping with the time zone part of the project2
#
[project2:/timezone]
harry = rw
sally = rw
ross = rw
* = r
The groups section can be used to define groups of users. For repository project1, only users from the group team1 have read/write access. All other users have read only access.
It is possible to define access for the entire repository, or for specific directory within repository.
Step 5:
In the end it is time to link the Apache server with the Subversion. This is done using the C:\etc\subversion.conf file:
<Location /project1>
DAV svn
SVNPath C:/Repositories/project1
AuthType Basic
AuthName "Subversion Project1 repository"
AuthUserFile c:/etc/svn-auth-file
Require valid-user
AuthzSVNAccessFile c:/etc/svn-acl
</Location>
<Location /project2>
DAV svn
SVNPath C:/Repositories/project2
AuthType Basic
AuthName "Subversion Project2 repository"
AuthUserFile c:/etc/svn-auth-file
Require valid-user
AuthzSVNAccessFile c:/etc/svn-acl
</Location>
The developers can access the “C:\Repositories\project1″ repository at the “http://subversion/project1” (http://localhost/project1/) URL. The access is only available to a valid user, and a basic HTTP authentication is used. The Apache server can read the valid user names and passwords from the “C:\etc\svn-auth-file” file. The “c:\etc\svn-acl” file defines the access rights to the repository.
Don’t forget to restart the Apache server for the configuration changes to take effect.
Conclusion
We have created the Subversion repositories, and configured an Apache server to access over network. User names and passwords have to be used to access the repositories, and different levels of access are given to different users. Congratulates, Subversion is configured successfully.
4. Backup
Having a central Version control system without a backup is a bad practice. In this section we need to create a system utility that will run on scheduled interval / manually, and dump all the changes made to a repository in a new file. Moving data to permanent storage i.e. DVD-ROM disk is not included in this article.
4.1. What to back up?
No doubt, these are our repositories to backup that we created earlier and used to store our data. In our article the dumps will stored in directory named “c:\backup\dumps”, you can select dump location of your choice. I also recommend backing up the c:\etc directory. I keep the latest version of the Apache “httpd.conf” file in it. This makes a total of 2 directories. Everything else can be downloaded from the Internet, if the worst happens.
It’s recommended to turn on the compression on the backup folder, to preserve space.
4.2. Creating a repository dump
Since writing programs is what I do, I have decided to use VB Script for the backup procedure. The script basically has a subroutine [CreateDump] that gets the last known revision number for a given repository, compares it to the current revision, and if necessary, dumps the most recent changes into a file.
To break this down further, the subroutine has five parameters:
- A name of the log file
- A name of the file containing the last know revision
- A command string for getting the youngest revision of the defined repository
- The repository that is to be dumped
- A fragment of the dump file name
In the example, for the Project1 the subroutine opens a log file, and compares the last know revision number [i.e. stored in the file c:\etc\proj1-last] to the youngest revision number for that repository. For example, if the last known revision number for repository “C:\Repositories\project1″ is 4712 and the youngest revision is 4738, the subroutine executes the following command:
“C:\Progra~1\Subversion\bin\svnadmin.exe dump C:\Repositories\project1 –revision 4712:4738 –incremental”
The dump is saved into a file “c:\backup\dumps\proj1-4712-4738.dmp”.
If the file “c:\etc\proj1-last” does not exist, the last known revision number is assumed to be 0 and the option –incremental is omitted from the dump command.
The example below creates backup files for two repositories. It uses two separate log files, but the script can easily be modified to only use one. But, it must use different lastFileName for each repository. It can be scheduled to run at your convenience. I run it once a day.
The script can be run with the following command:
“C:\windows\system32\cscript.exe c:\etc\backup.vbs”
The file backup.vbs is available for download.
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const folderName = "C:\backup\dumps\"
Const repositoryProj1 = "C:\Repositories\project1"
Const repositoryProj2 = "C:\Repositories\project2"
getYoungestProj1 = "C:\Progra~1\Subversion\bin\svnlook.exe youngest " + repositoryProj1
getYoungestProj2 = "C:\Progra~1\Subversion\bin\svnlook.exe youngest " + repositoryProj2
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set WshShell = CreateObject( "WScript.Shell" )
Call CreateDump( "C:\backup\proj1.log", "C:\etc\proj1-last", getYoungestProj1, repositoryProj1, "proj1" )
Call CreateDump( "C:\backup\proj2.log", "C:\etc\proj2-last", getYoungestProj2, repositoryProj2, "proj2" )
WScript.Quit( 0 )
'********************************************************************************
'*
'* End of script body
'*
'********************************************************************************
Sub CreateDump( logFileName, lastFileName, getYoungestCmd, repository, dumpName )
' Open the log file
Set objLogFile = objFSO.OpenTextFile( logFileName, ForAppending, True )
objLogFile.WriteLine Now & " - - Script started - -"
' Default last revision is 0
lastRev = 0
' Does the file exist?
If ( objFSO.FileExists( lastFileName ) ) Then
Set objFile = objFSO.GetFile( lastFileName )
' Does it contain anything?
If ( objFile.Size > 0 ) Then
Set objTextFile = objFSO.OpenTextFile( lastFileName, ForReading )
' Get the last revison and increase it by 1
lastRev = objTextFile.Readline
lastRev = lastRev + 1
End If
End If
' Execute the getYoungestCmd and read its output
Set objExec = WshShell.Exec( getYoungestCmd )
Do While ( objExec.Status <> 1 )
WScript.Sleep 100
Loop
youngest = objExec.StdOut.Readline
' Is the youngest revision above the last one?
If ( CLng( lastRev ) > CLng( youngest ) ) Then
objLogFile.WriteLine Now & " Exiting: lastRev (" & lastRev & ") > youngest (" & youngest & ")"
objLogFile.WriteLine Now & " Script done"
objLogFile.Close
Exit Sub
End If
' Compose the file name
dumpFileName = folderName & dumpName & "-" & lastRev & "-" & youngest & ".dmp"
' Add incremental, if not starting a new dump
incremental = ""
If ( lastRev > 0 ) Then
incremental = " --incremental"
End If
' Compose the dump command for the current repository
dumpCommand = "C:\Progra~1\Subversion\bin\svnadmin.exe dump " & repository & _
" --revision " & lastRev & ":" & youngest & incremental
' Open the destination file and execute the dump command
Set objDumpFile = objFSO.OpenTextFile( dumpFileName, ForWriting, True )
Set objExecDump = WshShell.Exec( dumpCommand )
' Read the dump output and write it to the file
Do While True
If Not objExecDump.StdOut.AtEndOfStream Then
input = objExecDump.StdOut.Read( 1 )
objDumpFile.Write input
Else
Exit Do
End If
Loop
objDumpFile.Close
' Write the latest revision into the file
Set objTextFile = objFSO.OpenTextFile( lastFileName, ForWriting, True )
objTextFile.Write youngest
objTextFile.Close
' Close the log file and exit
objLogFile.WriteLine Now & " Script done"
objLogFile.Close
End Sub
5. Upgrade
If you need to upgrade the Apache server, please follow below sections.
5.1. Upgrading Apache 2.2 server
Apache upgrade is a bit specific. Upgrade option is not available and you need to uninstall the currently installed version first. There is nothing much to it, just go to the Windows Control Panel \ Add or Remove Programs and select Remove.
Note: Before to proceed to uninstall Apache make sure to back up your latest httpd.conf file in a safe location.
After the un-installation you are left with a couple of folders, namely:
C:\Program Files\Apache Software foundation\Apache2.2\conf
C:\Program Files\Apache Software foundation\Apache2.2\logs
C:\Program Files\Apache Software foundation\Apache2.2\modules
Since Apache installation doesn’t like the fact that files and folder it is trying to create already exists, I suggest you rename the C:\Program Files\Apache Software foundation\Apache2.2 to something original, like C:\Program Files\Apache Software foundation\Apache2.2-old. That way you get to keep all your Apache log files. If you don’t need them you can delete the Apache2.2 folder all together.
Now you are ready to install the new Apache 2.2 server as described in section 2.3. Installing Apache 2.2. After that, all you need to put the old httpd.conf in the C:\Program Files\Apache Software foundation\Apache2.2\conf folder, copy the mod_authz_svn.so and mod_dav_svn.so into the C:\Program Files\Apache Software foundation\Apache2.2\modules folder, and you’re done. You have just successfully upgraded Apache 2.2 server.
5.2. Upgrading Subversion
Before you begin you need to decide whether you will keep your repositories as they are, or reload them from the dump files.
Let’s proceed with decision to reload them from my backups, because of the speedup in repository operations. It now takes much less time to commit, update or simply get file contents at specific revision. But loading from the dump a file takes some time, so if your backup has become too large, you may want keep the current repositories. If you want to keep your current database, this is what you need to do before you upgrade [taken from the Win32 release notes]:
***** IMPORTANT *** Upgrading from 1.1.x to 1.2.x *** IMPORTANT *****
In this release, we've upgraded BerkeleyDB from version 4.2.52 to
4.3.27. If you are currently using Subversion 1.1.x as a server on
Windows with BerkeleyDB, use the following steps to upgrade your
repositories:
-- Make sure nobody is using the repository (stop Apache/svnserve,
restrict access via file://).
-- For each repository, using the old (1.1.x) binaries:
-- Run "svnadmin recover <repos-dir>";
-- Create a backup of the repository;
-- Run "svnadmin list-unused-dblogs <repos-dir>"
and remove the listed files;
-- Delete all the "<repos-dir>\db\__db.00?" files.
-- Upgrade Subversion.
Once again, this is only necessary for repositories based on BDB.
You do NOT have to dump/reload your repositories.
*********************************************************************
You may also want to change your repositories from BDB to FSFS, or vice versa. In that case you will need to reload your repository from the dump files anyway. So, let’s start with the upgrade process.
Step 1:
First you need to make sure that nobody can access your repositories while you’re doing the upgrade, so stop the Apache server.
Step 2:
Make sure that your last backups contain the latest revision stored in your repositories. You can check your backup names against each repository head revision number by hand
svnlook youngest C:\Repositories\project2
OR you can simply run the backup script:
C:\windows\system32\cscript.exe c:\etc\backup.vbs
This will bring your backups up to date. You may want to transfer them to the tape, burn CD, or whatever you store the backups on.
Step 3 is only needed, if you want to reload your repositories from the dump files. If not, skip it.
Step 3:
If you have enough space on your disk, rename your “C:\Repositories” folder to something else, so you will have a binary backup of your current repositories.
Step 4:
At this point you can run the Subversion installation. The process is described in section 2.2. Installing Subversion with minor difference.
The installation process detects that you are running an Apache 2.2 server and notifies you, that it will stop its services, and restart them after the installation. Also, it offers to copy the mod_authz_svn.so and mod_dav_svn.so to the “C:\Program Files\Apache Software foundation\Apache2.2\modules” folder for you, but there is an error in the current installation of Subversion, which prevents this from happening.
After the installation is complete, check the Apache services, and stop them if they are running.
Steps 5, 6 and 7 only apply, if you have decided to reload your repositories from the dump files. If you have decided to keep your repositories unchanged, you may skip directly to step 8.
Step 5:
Recreate the directories first:
C:\Repositories\project1
C:\Repositories\project2
Step 6:
The repositories themselves; the default storage for the repository has changed from “BerkeleyDB” to “FSFS”, so you need to specify –fs-type bdb explicitly if you want to create a BerkeleyDB repository.
svnadmin create --fs-type bdb C:\Repositories\project1
svnadmin create --fs-type bdb C:\Repositories\project2
Step 7:
At this point you need to reload the repositories from the backup files, using the load command.
svnadmin load C:\Repositories\project1 < C:\backup\dumps\proj1-0-53.dmp
svnadmin load C:\Repositories\project1 < C:\backup\dumps\proj1-54-64.dmp
[ etc ]
svnadmin load C:\Repositories\project2 < C:\backup\dumps\proj2-0-32.dmp
svnadmin load C:\Repositories\project2 < C:\backup\dumps\proj2-33-109.dmp
[ etc ]
Step 8:
The last thing you need to do is manually copy the mod_authz_svn.so and mod_dav_svn.so files to the C:\Program Files\Apache Software foundation\Apache2.2\modules directory. The location of the files has changed with the version 1.2.0 and the MSI script doesn’t seem to be aware of that either. You can find both files in the C:\Program Files\Subversion\bin directory.
Step 9:
Start the Apache server.
Subversion is now upgraded to version 1.2.0, and if that is what you has decided, your repositories have been reloaded from revision 0 up with all your data, resulting in faster repository operations.
http://www.o2.co.uk/broadband/
Reference:
Please note again, this HOWTO was written originaly by Miha Vitorovic and appended by Mike later. I started hosting in 2006.



















