---
title: "安装和配置Windows下SVN开发环境"
author: "marshal"
date: "2008-01-04T17:08:53Z"
tags: []
slug: "windows-svn"
draft: false
lastmod: "2008-01-04T17:08:53Z"
id: 153131
url: "https://marshal.iteye.com/blog/153131"
---

**简介**

本文介绍在WindowsXP（在Windows2003下应该也可以）安装SVN(subversion)及其相关集成工具。

实现如下功能：


通过http访问版本控制器
通过Web应用程序设置用户认证和授权


**基本步骤**

**安装Apache Http Server**

下载最新版本的Apache Http Server Windows安装包。

下载地址：<http://apache.mirror.phpchina.com/httpd/binaries/win32/apache_2.2.6-win32-x86-no_ssl.msi>

通过安装向导默认安装即可。

***需要注意的是：*** Network domain，Server name和Email address都必须填写适当的内容。

安装完成后，通过http://localhost访问成功即可。

**安装SVN**

下载最新版本的Subversion安装包。

下载地址：<http://subversion.tigris.org/files/documents/15/39559/svn-1.4.5-setup.exe>

默认安装即可。

检查是否安装成功，在命令行中，输入：


```sh

svn --version

```


显示版本号既成功。

**创建一个svn repository**

创建svn repository（仓库）的根目录，比如*e:/svn*。

在命令行下，进入*e:/svn*。

输入如下命令：


```sh

svnadmin create documents

```


**升级svn支持apache2.2**

svn默认1.4.5版本，是基于apache2.0编译的。

使用Microsoft Visual C++ 6.0。

apache2.2版本，基于更新的C++.net环境。

下载svn1.4.5针对apache2.2的分发包（没有安装包，所以麻烦一点）。

地址是：<http://subversion.tigris.org/downloads/1.4.5-win32/apache-2.2/svn-win32-1.4.5.zip>

下载后，解压缩，并覆盖安装的svn目录即可。

**SVN与Apache的集成**

将安装后svn的bin目录下所有后缀是so的文件复制到apache的modules目录下。

将安装后svn的bin目录下所有后缀是dll的文件复制到apache的bin目录下，*如果提示是否覆盖，一定注意不要覆盖apache目录下的dll，主要是apr方面的dll*。

编辑*apache/conf/httpd.conf*文件：

找到配置文件中的LoadModule dav_module modules/mod_dav.so和LoadModule dav_fs_module modules/mod_dav_fs.so，将该两行前的#号去掉；

在上述内容后加入：

```sh

LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

```


在配置文件末尾添加如下内容：


```sh

<Location /svn>
<Location /svn>
DAV svn
SVNParentPath e:/svn

AuthType Basic
AuthName "Subversion Reporsitory"
AuthUserFile "D:/Program Files/Apache Software Foundation/Apache2.2/conf/svnpasswd"


AuthzSVNAccessFile "D:/Program Files/Apache Software Foundation/Apache2.2/conf/svnauthz"
Require valid-user 
</Location>

```


重启apache即可。

创建svn用户，在命令行中，进入*D:/rogram Files/Apache Software Foundation/Apache2.2/bin*目录，输入：


```sh

htpasswd -c ../conf/svnpasswd marshal

```


创建password文件，并且创建marshal用户。

在*conf*目录下创建*svnauthz*用于授权，以下是简单的文件内容：

```sh

[/]
marshal = rw

```


上述文件为刚创建的*marshal*用户设置了对所有目录的读写的权限。

重启apache，并访问<http://localhost/svn/documents>

如有问题，通过*apache/logs/error.log*检查问题。


**安装SVNManager**

安装svnmanager，用于通过web的方式：


创建用户和修改密码
创建和修改用户权限
创建用户组和修改用户组的权限
创建SVN库


安装svnmanager，需要安装PHP环境和MySQL。

安装php环境，可参考：<http://marshal.iteye.com/blog/147139>或者其他文档。

安装MySQL，本文使用MySQL 5.0.45安装包默认安装即可。

为svnmanager创建数据库：


```shell

create database svnmanager CHARACTER SET utf8;

```


svnmanager网址：<http://svnmanager.sourceforge.net/>

svn需要PHP支持PEAR。

进入php的*PEAR*目录，命令行输入：


```sh

php go-pear.phar

```


出现提示的时候，回车即可。

svn需要VersionControl_SVN，这需要通过PEAR安装：


```sh

pear install -a VersionControl_SVN-0.3.1

```


当前svnmanager版本是*1.03*。

另外，需要修改php.ini文件，取消下列行的注释：


```sh

extension = php_mbstring.dll
extension = php_mysql.dll
extension = php_gb2.dll
extension = php_mysqli.dll
extension = php_pdo.dll
extension = php_pdo_mysql.dll

```


下载svnmanager，路径为：<http://sourceforge.net/project/showfiles.php?group_id=135933>

在*apache/htdocs*目录下，建一个目录*svnmanager*。

将下载的文件解压缩到上述的*svnmanager*中。

将*svnmanager*目录中的config.php.win改名为*config.php*。

修改文件中的内容如下：


```PHP

<?php
//
//  SVNManager config.php file for Windows based servers
//

$htpassword_cmd     = "D:\\Program Files\\Apache Software Foundation\\Apache2.2\\bin\\htpasswd";
$svn_cmd            = "D:\\Program Files\\Subversion\\bin\\svn";
$svnadmin_cmd       = "D:\\Program Files\\Subversion\\bin\\svnadmin";

//Subversion locations
$svn_repos_loc 			= 	"e:\\svn";
$svn_passwd_file 		= 	"D:\\Program Files\\Apache Software Foundation\\Apache2.2\\conf\\svnpasswd";
$svn_access_file 		= 	"D:\\Program Files\\Apache Software Foundation\\Apache2.2\\conf\\svnauthz";

//If the following is set, removing a repository will cause it to be
//moved to this location rather than being deleted.
$svn_trash_loc			=	"";

// If $svnserve_user_file is defined, then SVNManager will create a
// user/password file suitable for use with SVNSERVE
//
// When not set, this feature isn't enabled.
//
// Warning: When enabled, this mode requires that passwords are stored in the database readable!
// 
// Note: When is feature is enabled later, passwords need to be re-set before they are included in
//  	 the svnserve user file.
//
//$svnserve_user_file		=	"c:\\svn\\svnserve_passwd_file"; 
$svnserve_user_file = "";

//SMTP Server for outgoing mail
$smtp_server 			= 	"smtp.mailserver.net";


//Data Source Name (only tested with mysql and sqlite databases!!)
//
//Either:
// 
//Use the createtables.sql script to build the tables in a mysql database
// 
// or
//
//An empty SQLite database will automatically be generated with the first
//startup! 
//
//Please note that if you change the directory for a SQLite database that you
//choose a location that is not accessible via web!!
//

$dsn = "mysql://root:password@localhost/svnmanager";

//$dsn = "mysql://svnmanager:svnmgmpw@localhost/svnmanager";
//The following location is not readable from internet by means of an .htaccess file
//$dsn = "sqlite://svnmanager\\svnmanager.db";						

//Administrator account
//
//This account can be used to create a first administrator user.
//When an administrator user is added, this account doesn't work
//anymore!
//
$admin_name          = "admin";
$admin_temp_password = "admin";

// If $post_create_script is defined, then this script / command will be
// executed after a repository is created. 
// When the script/command is executed the one and only parameter will be
// the physical location of the repository.
// This might copy a default set of hooks or config files
//
// $post_create_script = "svn-update-config-files.bat";

?>

```


重启apache，然后通过<http://localhost/svnmanager>访问。

用户名/密码都是：admin

创建第一个用户，通过user admin链接，点击add按钮。

注意构选admin复选项。

通过刚刚创建的用户登录，就可以看到各种功能的链接。

以后就可以通过该界面创建用户和权限了，而不需要再通过svn和apache的命令和配置文件了。

另外，可下载中文汉化包，见：<http://bbs.iusesvn.com/viewthread.php?tid=2122>

本文最早由本人（marshal@javaeye）发表在：http://marshal.easymorse.com/blog/archives/161