Setting up Subversion and websvn on Debian | HowtoForge - Linux Howtos and Tutorials

来源:百度文库 编辑:神马文学网 时间:2024/04/27 18:24:31

Setting up Subversion and websvn on Debian

Submitted by bertheymans (Contact Author) (Forums) on Sun, 2006-09-10 15:02. :: Debian | Other

Setting up Subversion and websvn on Debian 

Purpose of this howto

This howto will illustrate a way to install and configureSubversion and websvn on a Debian server with the following features:

  • multiple repository Subversion
  • access to the repositories via WebDAV (http, https) and ssh
  • Linux system account access control and/or Apache level access control
  • a secured websvn (php web application for easy code browsing)
  • configured syntax coloring in websvn with gnu enscript
I will not specifically configure inetd with svnserve in this howto. Rest assured that Subversion will be totally functional without it.You can copy/paste most of the howto to get it working.

Packages that are assumed to already be installed

This howto assumes PHP and apache2 are installed and configured. Configuring apache2 with SSL is optional.

Setting up Subversion

Subversion packages

As root you can enter the following commands to install the packages required for our Subversion setup:

# apt-get update
# apt-get install subversion
# apt-get install libapache2-svn

The package libapache2-svn will install the subversion WebDAV apache module.

Creating and populating repositories

To work with in this howto we'll create two repos:

# mkdir /var/svn-repos/
# svnadmin create --fs-type fsfs /var/svn-repos/project_zen
# svnadmin create --fs-type fsfs /var/svn-repos/project_wombat 

The repository directories need the proper permissions for apache and the other users. I'll make a group and add users to it (don't just copy/paste here). The apache user won't be put in the group because I find it less secure.

# groupadd subversion
# addgroup john subversion
# addgroup bert subversion
# addgroup you subversion
...
# chown -R www-data:subversion /var/svn-repos/*
# chmod -R 770 /var/svn-repos/*

Let's set up easy ssh connectivity, on a user machine enter the following commands:

$ mkdir ~/.ssh/
$ cd ~/.ssh/
$ ssh-keygen -t dsa
$ cat ~/.ssh/id_dsa.pub | ssh you@example.com "cat - >> ~/.ssh/authorized_keys"

The server example.com is the server we installedSubversion on. For easy ssh use you can chose not to use a passphrasewith your key or use an agent to keep authenticated. Otherwise eachtransaction between the user machine and Subversion will require theuser to enter a password (very inconvenient). Using an agent can bedone like this:

$ ssh-agent
$ ssh-add
$ ssh you@example.com

All should be set now to use the a repository. You may test it like this, it shows an import and a checkout:

$ mkdir ~/TEMP/
$ echo "testing svn" > ~/TEMP/testing.txt
$ svn import -m "importing test over ssh+svn" ~/TEMP/ svn+ssh://example.com/var/svn-repos/project_zen/trunk
$ svn co svn+ssh://example.com/var/svn-repos/project_zen/trunk testcheckout

As a result the testing.txt file should be in a directory called testcheckout. On the serverside you can check the repositories with svnlook.

# svnlook tree /var/svn-repos/project_zen/

Configuring Subversion WebDAV

Normally the apache mod will be enabled by default, to ensure this is true enter the following commands:

# a2enmod dav
# a2enmod dav_svn

Configuration is done in the file /etc/apache2/mods-available/dav_svn.conf, but first we'll make an access file.

# htpasswd2 -c /etc/apache2/dav_svn.passwd you
# htpasswd2 /etc/apache2/dav_svn.passwd john
# htpasswd2 /etc/apache2/dav_svn.passwd sten
...

This is the content my /etc/apache2/mods-available/dav_svn.conf file:


DAV svn
SVNPath /var/svn-repos/project_zen
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
SSLRequireSSL



DAV svn
SVNPath /var/svn-repos/project_wombat
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
SSLRequireSSL

You can uncomment the SSLRequireSSL file if you don't want to use SSL, but then you need to use http and not httpsin the commands that follow. Apache should be restarted and we can testfrom a user machine. We'll import the same testfile in the wombatproject.

# /etc/init.s/apache2 restart
$ svn import -m "testing over https" https://example.com/svn_wombat ~/TEMP/

Using a webbrowser you can visit your URL https://example.com/svn_wombatand see what was just committed. This is a basic on-line view on therepository, but using a web font-end like websvn will offer a betterrepository browsing experience.

Setting up websvn

Required packages

To get rolling with websvn we'll need to install the followingpackages, both will show you configuration screens (explained in thenext paragraph):

# apt-get install enscript
# apt-get install websvn

Enscript isn't mandatory but we'll need it for syntax coloring in websvn.

Configuration

Enscript will ask for paper size, this might seem awkwardbut that's because enscript is also used for converting ASCII files toPostScript. We need it for it's syntax coloring features.

Websvn will first ask for which kind of server to configure, go ahead and just press enter.

 The next screens ask for a parent repository folder (/var/svn-repos/in this case) and specific repository folders, this will determinewhich repositories will show up in websvn. We will only enter a parentrepository, all repositories created in this folder will show up inwebsvn for users to browse. If you want to show only specificrepositories enter their full paths in the second screen and leave theparent path blank.
 As a result the file /etc/websvn/svn_deb_conf.inc will be written. You can rerun debian package configuration screens with dpkg-reconfigure. Further websvn configuration is done in the file /etc/websvn/config.inc. This is the content of my file with some extension mappings for the syntax coloring.
// --- LOOK AND FEEL ---
//
// Uncomment ONLY the display file that you want.
$config->setTemplatePath("$locwebsvnreal/templates/Standard/");
// $config->setTemplatePath("$locwebsvnreal/templates/BlueGrey/");
// $config->setTemplatePath("$locwebsvnreal/templates/Zinn/");
// $contentType[".c"] = "plain/text"; // Create a new association
// $contentType[".doc"] = "plain/text"; // Modify an existing one
unset($contentType[".sh"]); // Remove a default association -> .sh is regarded as a binary file by default, needs to be unset
// --- COLOURISATION ---
// Uncomment this line if you want to use Enscript to colourise your file listings
//
// You'll need Enscript version 1.6 or higher AND Sed installed to use this feature.
// Set the path above.
//
$config->useEnscript();
// Enscript need to be told what the contents of a file are so that it can be colourised
// correctly. WebSVN includes a predefined list of mappings from file extension to Enscript
// file type (viewable in setup.inc).
//
// Here you should add and other extensions not already listed or redefine the default ones. eg:
//
// php is default correctly colourized
$extEnscript[".java"] = "java";
$extEnscript[".pl"] = "perl";
$extEnscript[".py"] = "python";
$extEnscript[".sql"] = "sql";
$extEnscript[".java"] = "java";
$extEnscript[".html"] = "html";
$extEnscript[".xml"] = "html";
$extEnscript[".thtml"] = "html";
$extEnscript[".tpl"] = "html";
$extEnscript[".sh"] = "bash";
// --- MISCELLANOUS ---
// Uncomment this if you don't have the right to use it. Be warned that you may need it however!
set_time_limit(0);
// Comment this line to turn off caching of repo information. This will slow down your browsing.
$config->setCachingOn();
// Number of spaces to expand tabs to in diff/listing view across all repositories
$config->expandTabsBy(8);
// To change the global option for individual repositories, uncomment and replicate
// the required line below (replacing 'myrep' for the name of the repository to be changed).
// $config->findRepository("myrep")->expandTabsBy(3); // Expand Tabs by 3 for repository 'myrep'
?>
if ( file_exists("/etc/websvn/svn_deb_conf.inc") ) {
include("/etc/websvn/svn_deb_conf.inc");
}
?>

Next up is configuring the apache virtualhost for websvn.
Example using SSL:


ServerAdmin webmaster@example.com
ServerName svn.example.com
DocumentRoot /var/www/websvn/

Options FollowSymLinks
order allow,deny
allow from all
AuthType Basic
AuthName "Subversion Repository"
Require valid-user
AuthUserFile /etc/apache2/dav_svn.passwd

php_flag magic_quotes_gpc Off
php_flag track_vars On


SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem

Example without SSL:


ServerAdmin webmaster@example.com
ServerName svn.example.com
DocumentRoot /var/www/websvn/


Options FollowSymLinks
AllowOverride None
order allow,deny
allow from all
AuthType Basic
AuthName "Subversion Repository"
Require valid-user
AuthUserFile /etc/apache2/dav_svn.passwd

php_flag magic_quotes_gpc Off
php_flag track_vars On



Restart apache and have a look at the result at your https://svn.example.com/.