如何在 GNU/Linux-Ubuntu 上设置 Subversion (SVN)服务器

我有一台运行 Ubuntu 的笔记本电脑,我想作为一个 Subversion 服务器。既可以让我在本地承担责任,也可以让其他人远程承担责任。需要采取哪些步骤才能使其正常工作?请包括以下步骤:

  • 获取并配置 Apache 和必要的模块(我知道还有其他方法可以创建 SVN 服务器,但我希望它是专门针对 Apache 的)
  • 配置访问服务器的安全方法(SSH/HTTPS)
  • 配置一组授权用户(例如,他们必须被授权提交,但是可以自由浏览)
  • 使用初始提交(类似于“ Hello world”)验证设置

这些步骤可以包括命令行或 GUI 应用程序指令的任意混合。如果可以,请注意哪些指令是特定于特定发行版或版本的,以及哪些地方可以使用用户选择的特定工具(例如,纳米机器人而不是 Vi)。

215070 次浏览

For Apache:

sudo apt-get -yq install apache2

For SSH:

sudo apt-get -yq install openssh-server

For Subversion:

sudo apt-get -yq install subversion subversion-tools

If you'd like you can combine these into one command like:

sudo apt-get -yq install apache2 openssh-server subversion subversion-tools

I can't help with the rest...

Steps I've taken to make my laptop a Subversion server. Credit must go to AlephZarro for his directions here. I now have a working SVN server (which has currently only been tested locally).

Specific setup: Kubuntu 8.04 Hardy Heron

Requirements to follow this guide:

  • apt-get package manager program
  • text editor (I use kate)
  • sudo access rights

1: Install Apache HTTP server and required modules:

sudo apt-get install libapache2-svn apache2

The following extra packages will be installed:

apache2-mpm-worker apache2-utils apache2.2-common

2: Enable SSL

sudo a2enmod ssl
sudo kate /etc/apache2/ports.conf

Add or check that the following is in the file:

<IfModule mod_ssl.c>
Listen 443
</IfModule>

3: Generate an SSL certificate:

sudo apt-get install ssl-cert
sudo mkdir /etc/apache2/ssl
sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem

4: Create virtual host

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/svnserver
sudo kate /etc/apache2/sites-available/svnserver

Change (in ports.conf):

"NameVirtualHost *" to "NameVirtualHost *:443"

and (in svnserver)

<VirtualHost *> to <VirtualHost *:443>

Add, under ServerAdmin (also in file svnserver):

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLProtocol all
SSLCipherSuite HIGH:MEDIUM

5: Enable the site:

sudo a2ensite svnserver
sudo /etc/init.d/apache2 restart

To overcome warnings:

sudo kate /etc/apache2/apache2.conf

Add:

"ServerName $your_server_name"

6: Adding repository(ies): The following setup assumes we want to host multiple repositories. Run this for creating the first repository:

sudo mkdir /var/svn


REPOS=myFirstRepo
sudo svnadmin create /var/svn/$REPOS
sudo chown -R www-data:www-data /var/svn/$REPOS
sudo chmod -R g+ws /var/svn/$REPOS

6.a. For more repositories: do step 6 again (changing the value of REPOS), skipping the step mkdir /var/svn

7: Add an authenticated user

sudo htpasswd -c -m /etc/apache2/dav_svn.passwd $user_name

8: Enable and configure WebDAV and SVN:

sudo kate /etc/apache2/mods-available/dav_svn.conf

Add or uncomment:

<Location /svn>
DAV svn


# for multiple repositories - see comments in file
SVNParentPath /var/svn


AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
SSLRequireSSL
</Location>

9: Restart apache server:

sudo /etc/init.d/apache2 restart

10: Validation:

Fired up a browser:

http://localhost/svn/$REPOS
https://localhost/svn/$REPOS

Both required a username and password. I think uncommenting:

<LimitExcept GET PROPFIND OPTIONS REPORT>


</LimitExcept>

in /etc/apache2/mods-available/dav_svn.conf, would allow anonymous browsing.

The browser shows "Revision 0: /"

Commit something:

svn import --username $user_name anyfile.txt https://localhost/svn/$REPOS/anyfile.txt -m “Testing”

Accept the certificate and enter password. Check out what you've just committed:

svn co --username $user_name https://localhost/svn/$REPOS

Following these steps (assuming I haven't made any error copy/pasting), I had a working SVN repository on my laptop.

If you get 403 forbidden when you hit the webserver it may be because you used a hostname that is not what you specified in your config file (ie localhost or 127.0.0.1). Try hitting https://whateveryousetasyourhostname instead...

Afterwards, I needed to execute (within the context of the example quoted above)

$ sudo chmod g+w /var/svn/$REPOS/db/rep-cache.db

$ sudo chown www-data:www-data /var/svn/$REPOS/db/rep-cache.db

Otherwise I kept receiving a 409 error when committing local modifications (though the commitments were server side effective, I needed to follow up with local updates)

Please write a single command on the terminal.

To open the terminal please press Ctrl + Alt + T, and then type this command:

$sudo apt-get install subversion