Apache

使用Apache服务器配置SVN服务器的过程

2010年项目开发过程中 试用了svn作为版本控制,使用TortoiseSVN客户端,同时用apache配置成浏览器访问,更加方便,此文就是记录配置过程,记录解决问题过程的。
安装
apt-get install subversion subversion-tools apache2 libapache2-svn

创建储存库
svnadmin create /home/machine/svn/aviation
创建一个新的空储存库,数据储存方式默认采用Berkeley DB。

导入源码
svn import /home/machine/jdeproject/aviation file:////home/machine/svn/aviation

配置
配置文件位于/etc/apache2/mods-enabled/目录下,配置文件共有两个,分别是dav_svn.conf和dav_svn.load,dav_svn.load文件负责装载必要的模块,dav_svn.conf是mod_dav_svn.so模块的配置文件,修改:  


# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.


# <Location URL> ... </Location>
 # URL controls how the repository appears to the outside world.
 # In this example clients access the repository as http://hostname/svn/
 # Note, a literal /svn should NOT exist in your document root.
 
   #设置访问路径
   <Location /aviation>
 
   # Uncomment this to enable the repository
   #启用
   DAV svn
 
   # Set this to the path to your repository
   #设置储存库路径,仅支持单个储存库,该路径要可被Apache进程访问。
   SVNPath /home/machine/svn/aviation
   # Alternatively, use SVNParentPath if you have multiple repositories under
   # under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
   # You need either SVNPath and SVNParentPath, but not both.
   #SVNParentPath /var/lib/svn
 
   # Access control is done at 3 levels: (1) Apache authentication, via
   # any of several methods.  A "Basic Auth" section is commented out
   # below.  (2) Apache <Limit> and <LimitExcept>, also commented out
   # below.  (3) mod_authz_svn is a svn-specific authorization module
   # which offers fine-grained read/write access control for paths
   # within a repository.  (The first two layers are coarse-grained; you
   # can only enable/disable access to an entire repository.)  Note that
   # mod_authz_svn is noticeably slower than the other two layers, so if
   # you don't need the fine-grained control, don't configure it.
 
   # Basic Authentication is repository-wide.  It is not secure unless
   # you are using https.  See the 'htpasswd' command to create and
   # manage the password file - and the documentation for the
   # 'auth_basic' and 'authn_file' modules, which you will need for this
   # (enable them with 'a2enmod').
   #启用Apache基础验证
   AuthType Basic
   #设置验证框标题
   AuthName "Subversion Repository"
   #指定验证用户文件名
   AuthUserFile /etc/apache2/dav_svn.passwd
 
   # To enable authorization via mod_authz_svn
   #启用目录级别授权,dav_svn.authz是授权配置文档
   #AuthzSVNAccessFile /etc/apache2/dav_svn.authz
 
   # The following three lines allow anonymous read, but make
   # committers authenticate themselves.  It requires the 'authz_user'
   # module (enable it with 'a2enmod').
   #<LimitExcept GET PROPFIND OPTIONS REPORT>
   #允许匿名访问,不允许Commit,不能与AuthzSVNAccessFile同时使用
   Require valid-user
   #</LimitExcept>
 
 </Location>


权限修改
修改/home/machine/jdeproject/aviation/目录访问权限使它可被Apache进程访问,也就是其他用户可访问. drwxr-xr-x 6 machine machine 4096 10-27 19:25 aviation

添加授权

通过Apache的用户验证功能可以区别匿名用户和验证用户,从而赋予匿名用户读权限和验证用户读/写的权限。授权文档dav_svn.conf定义:etc/apache2/dav_svn.authz,它的内容如下:
# 定义组
[groups]             
# 定义admin组及组内的用户
admin = machine
# 定义user组及组内的用户
users = zhao,song # 定义根的权限
[/]        
# 全部用户不具备任何权限
*=              
# admin组具备读写权限       
@admin = rw     
# user具备只读权限
@user = r        

 添加用户
htpasswd -c /etc/apache2/dev_svn.passwd machine
New password:
Re-type new password:
#省略添加其他用户的过程,注意参数,首次创建需要-c,增加的时候只要-d
htpasswd -d /etc/apache2/dev_svn.passwd song
New password:
Re-type new password:

使用
现在可以在浏览器中输入http://127.0.0.1/aviation访问源代码,可以使用svn客户端管理源代码了。:)