个人工具

“UbuntuHelp:Subversion”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/Subversion}}
 
{{From|https://help.ubuntu.com/community/Subversion}}
 
{{Languages|UbuntuHelp:Subversion}}
 
{{Languages|UbuntuHelp:Subversion}}
 
 
 
'''This wiki document explains how to setup Subversion alias
 
'''This wiki document explains how to setup Subversion alias
 
SVN on Ubuntu. The intended audience is experienced Linux users and system administrators.'''
 
SVN on Ubuntu. The intended audience is experienced Linux users and system administrators.'''
 
 
=== Introduction ===
 
=== Introduction ===
 
 
If you are new to Subversion, this section provides a quick introduction.
 
If you are new to Subversion, this section provides a quick introduction.
 
 
Subversion is an open source version control system. Using
 
Subversion is an open source version control system. Using
 
Subversion, you can record the history of source files and
 
Subversion, you can record the history of source files and
第16行: 第11行:
 
is much like an ordinary file server, except that it remembers
 
is much like an ordinary file server, except that it remembers
 
every change ever made to files and directories.
 
every change ever made to files and directories.
 
 
=== Assumptions ===
 
=== Assumptions ===
 
 
It is assumed that you are aware of how to run Linux commands,
 
It is assumed that you are aware of how to run Linux commands,
 
edit files, start/stop services in an Ubuntu
 
edit files, start/stop services in an Ubuntu
第24行: 第17行:
 
have [[UbuntuHelp:RootSudo|sudo access]] and you
 
have [[UbuntuHelp:RootSudo|sudo access]] and you
 
want to use Subversion software.
 
want to use Subversion software.
 
 
It is also assumed you have an internet connection.
 
It is also assumed you have an internet connection.
 
 
=== Scope of this document ===
 
=== Scope of this document ===
 
 
To make an SVN repository available to access using the HTTP protocol, you
 
To make an SVN repository available to access using the HTTP protocol, you
 
must install & configure web server. Apache 2 is proven to work
 
must install & configure web server. Apache 2 is proven to work
第34行: 第24行:
 
scope of this document. However, the configuration of Apache 2 Webserver
 
scope of this document. However, the configuration of Apache 2 Webserver
 
for SVN is covered in this document.
 
for SVN is covered in this document.
 
 
To access an SVN repository using HTTPS protocol, you
 
To access an SVN repository using HTTPS protocol, you
 
must install & configure digital certificate in your Apache 2 web server.
 
must install & configure digital certificate in your Apache 2 web server.
 
The installation and configuration of digital certificate is beyond the
 
The installation and configuration of digital certificate is beyond the
 
scope of this document. (See [[UbuntuHelp:forum/server/apache2/SSL|forum/server/apache2/SSL]].)
 
scope of this document. (See [[UbuntuHelp:forum/server/apache2/SSL|forum/server/apache2/SSL]].)
 
 
=== Installation ===
 
=== Installation ===
 
 
Subversion is already in the main repository. So, to install Subversion you can simply install the following packages <code><nowiki>subversion</nowiki></code> (see InstallingSoftware).
 
Subversion is already in the main repository. So, to install Subversion you can simply install the following packages <code><nowiki>subversion</nowiki></code> (see InstallingSoftware).
 
 
If it fails reporting dependencies, please locate the
 
If it fails reporting dependencies, please locate the
 
packages and install them. If it reports any other issues,
 
packages and install them. If it reports any other issues,
 
please resolve them. If you cannot resolve the issue,
 
please resolve them. If you cannot resolve the issue,
 
please refer the mailing list archive of those packages.
 
please refer the mailing list archive of those packages.
 
 
=== Server Configuration ===
 
=== Server Configuration ===
 
 
This step assumes you have installed above mentioned packages
 
This step assumes you have installed above mentioned packages
 
on your system. This section explains how to create SVN repository and
 
on your system. This section explains how to create SVN repository and
 
access the project.
 
access the project.
 
 
==== Create SVN Repository ====
 
==== Create SVN Repository ====
 
 
There are several typical places to put a Subversion repository;
 
There are several typical places to put a Subversion repository;
 
most common places are: srv/svn, /usr/local/svn and /home/svn. For clarity's sake, we'll
 
most common places are: srv/svn, /usr/local/svn and /home/svn. For clarity's sake, we'll
 
assume we are putting the Subversion repository in /home/svn, and your
 
assume we are putting the Subversion repository in /home/svn, and your
 
project's name is simply 'myproject'
 
project's name is simply 'myproject'
 
 
There are also several common ways to set permissions on your repository. However,
 
There are also several common ways to set permissions on your repository. However,
 
this area is the most common source of errors in installation, so we will cover it
 
this area is the most common source of errors in installation, so we will cover it
 
thoroughly. Typically, you should choose to create a new group called 'Subversion' that
 
thoroughly. Typically, you should choose to create a new group called 'Subversion' that
 
will own the repository directory. To do this (see [AddUsersHowto] for details):
 
will own the repository directory. To do this (see [AddUsersHowto] for details):
 
+
# Choose System >  Administration > Users and Groups from your Ubuntu menu.
* Choose System >  Administration > Users and Groups from your Ubuntu menu.
+
# Select the Group tab
 
+
# Click the 'Add Group' button
* Select the Group tab
+
# Name the group 'subversion'
 
+
# Add yourself and www-data (the Apache user) as users to this group
* Click the 'Add Group' button
+
# Select 'OK' to commit your changes and exit the app.
 
+
* Name the group 'subversion'
+
 
+
* Add yourself and www-data (the Apache user) as users to this group
+
 
+
* Select 'OK' to commit your changes and exit the app.
+
 
+
 
You have to logout and login again before you are a member of the subversion group, and can do check ins.
 
You have to logout and login again before you are a member of the subversion group, and can do check ins.
 
 
Now issue the following commands:
 
Now issue the following commands:
 
<pre><nowiki>
 
<pre><nowiki>
第90行: 第63行:
 
$ sudo chmod -R g+rws myproject
 
$ sudo chmod -R g+rws myproject
 
</nowiki></pre>
 
</nowiki></pre>
 
 
The last command sets gid for proper permissions on all new files added to your
 
The last command sets gid for proper permissions on all new files added to your
 
Subversion repository.
 
Subversion repository.
 
 
 
The SVN repository can be created using the following command:
 
The SVN repository can be created using the following command:
 
<pre><nowiki>
 
<pre><nowiki>
 
$ sudo svnadmin create /home/svn/myproject
 
$ sudo svnadmin create /home/svn/myproject
 
</nowiki></pre>
 
</nowiki></pre>
 
 
If you want to use WebDAV as an access method described below, repeat the chmod -R g+rws myproject command again. This is because svnadmin will create directories and files without group write access. This is no problem for read only access or using the custom svn protocol but when Apache tries to commit changes to the repository linux will deny it access.
 
If you want to use WebDAV as an access method described below, repeat the chmod -R g+rws myproject command again. This is because svnadmin will create directories and files without group write access. This is no problem for read only access or using the custom svn protocol but when Apache tries to commit changes to the repository linux will deny it access.
 
Also the owner and group are set as root. This can be changed by repeating the chown and chgrp commands listed above.
 
Also the owner and group are set as root. This can be changed by repeating the chown and chgrp commands listed above.
 
 
=== Access Methods ===
 
=== Access Methods ===
 
 
Subversion repositories can be accessed (checkout) through many different
 
Subversion repositories can be accessed (checkout) through many different
 
methods-on local disk, or through various network protocols. A
 
methods-on local disk, or through various network protocols. A
 
repository location, however, is always a URL. The table describes how
 
repository location, however, is always a URL. The table describes how
 
different URL schemas map to the available access methods.
 
different URL schemas map to the available access methods.
 
 
{|border="1" cellspacing="0"
 
{|border="1" cellspacing="0"
 
|'''Schema''' ||  '''Access Method'''                     
 
|'''Schema''' ||  '''Access Method'''                     
第123行: 第89行:
 
| svn+ssh://  || Same as svn://, but through an SSH tunnel  
 
| svn+ssh://  || Same as svn://, but through an SSH tunnel  
 
|}
 
|}
 
 
In this section, we will see how to configure SVN for all these access
 
In this section, we will see how to configure SVN for all these access
 
methods.  Here, we cover the basics. For more advanced usage details,
 
methods.  Here, we cover the basics. For more advanced usage details,
 
you are always recommended to refer the [http://svnbook.red-bean.com/ svn book].
 
you are always recommended to refer the [http://svnbook.red-bean.com/ svn book].
 
 
==== Direct repository access (file://) ====
 
==== Direct repository access (file://) ====
 
 
This is the simplest of all access methods. It does not require any
 
This is the simplest of all access methods. It does not require any
 
SVN server process to be running. This access method is used to access
 
SVN server process to be running. This access method is used to access
 
SVN from the same machine. The syntax is as follows:
 
SVN from the same machine. The syntax is as follows:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
$ svn co file:///home/svn/myproject
 
$ svn co file:///home/svn/myproject
第139行: 第101行:
 
$ svn co file://localhost/home/svn/myproject
 
$ svn co file://localhost/home/svn/myproject
 
</nowiki></pre>
 
</nowiki></pre>
 
 
''NOTE: Please note, if you do not specify the hostname, you must use
 
''NOTE: Please note, if you do not specify the hostname, you must use
 
three forward slashes (///). If you specify the hostname, you must use
 
three forward slashes (///). If you specify the hostname, you must use
 
two forward slashes (//).''
 
two forward slashes (//).''
 
 
The repository permission is depend on filesystem permission. If the
 
The repository permission is depend on filesystem permission. If the
 
user has read/write permission, he can checkout/commit the changes to the
 
user has read/write permission, he can checkout/commit the changes to the
 
repository. If you set permissions as above, you can give new users the ability
 
repository. If you set permissions as above, you can give new users the ability
 
to checkout/commit by simply adding them to the Subversion group you added above.
 
to checkout/commit by simply adding them to the Subversion group you added above.
 
 
==== Access via WebDAV protocol (http://) ====
 
==== Access via WebDAV protocol (http://) ====
 
 
To access the SVN repository via WebDAV protocol, you must configure
 
To access the SVN repository via WebDAV protocol, you must configure
 
your Apache 2 web server.  
 
your Apache 2 web server.  
 
 
First install the following package <code><nowiki>libapache2-svn</nowiki></code> (see InstallingSoftware).
 
First install the following package <code><nowiki>libapache2-svn</nowiki></code> (see InstallingSoftware).
 
 
You must add the following snippet in your
 
You must add the following snippet in your
 
/etc/apache2/mods-available/dav_svn.conf file:
 
/etc/apache2/mods-available/dav_svn.conf file:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
<Location /svn/myproject>
 
<Location /svn/myproject>
第171行: 第126行:
 
</Location>
 
</Location>
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Alternatively, you can allow svn access on a per-site basis. This is done by adding the previous snippet into the desired site configuration file located in
 
Alternatively, you can allow svn access on a per-site basis. This is done by adding the previous snippet into the desired site configuration file located in
 
<code><nowiki>/etc/apache2/sites-available/</nowiki></code> directory.
 
<code><nowiki>/etc/apache2/sites-available/</nowiki></code> directory.
 
 
Once you add the above lines, you must restart apache2 web server. To restart apache2
 
Once you add the above lines, you must restart apache2 web server. To restart apache2
 
web server, you can run the following command:
 
web server, you can run the following command:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo /etc/init.d/apache2 restart
 
sudo /etc/init.d/apache2 restart
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Next, you must create /etc/subversion/passwd file. This file contains
 
Next, you must create /etc/subversion/passwd file. This file contains
 
user authentication details.  
 
user authentication details.  
 
 
If you have just installed SVN, the passwd file will not yet exist and needs to be created using the "-c" switch. Adding any users after that should be done without the "-c" switch to avoid overwriting the passwd file.
 
If you have just installed SVN, the passwd file will not yet exist and needs to be created using the "-c" switch. Adding any users after that should be done without the "-c" switch to avoid overwriting the passwd file.
 
 
To add the first entry, ie.. to add the first user, you can run the following command:
 
To add the first entry, ie.. to add the first user, you can run the following command:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo htpasswd -c /etc/subversion/passwd user_name
 
sudo htpasswd -c /etc/subversion/passwd user_name
 
</nowiki></pre>
 
</nowiki></pre>
 
 
It prompts you to enter the password. Once you enter the password, the user is added.
 
It prompts you to enter the password. Once you enter the password, the user is added.
 
 
To add more users after that, you can run the following command:
 
To add more users after that, you can run the following command:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo htpasswd /etc/subversion/passwd second_user_name
 
sudo htpasswd /etc/subversion/passwd second_user_name
 
</nowiki></pre>
 
</nowiki></pre>
 
 
If you are uncertain whether the passwd file exists, running the command below will tell you whether the file already exists:
 
If you are uncertain whether the passwd file exists, running the command below will tell you whether the file already exists:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
cat /etc/subversion/passwd
 
cat /etc/subversion/passwd
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Now, to access the repository you can run the
 
Now, to access the repository you can run the
 
following command:
 
following command:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
$ svn co http://hostname/svn/myproject myproject --username user_name
 
$ svn co http://hostname/svn/myproject myproject --username user_name
 
</nowiki></pre>
 
</nowiki></pre>
 
 
It prompts you to enter the password. You must enter the password
 
It prompts you to enter the password. You must enter the password
 
configured using htpasswd2 command. Once it is authenticated the
 
configured using htpasswd2 command. Once it is authenticated the
 
project is checked out.
 
project is checked out.
 
 
'''WARNING: The password is transmitted as plain text. If you are worried
 
'''WARNING: The password is transmitted as plain text. If you are worried
 
about password snooping, you are advised to use SSL encryption. For
 
about password snooping, you are advised to use SSL encryption. For
 
details, please refer next section.'''
 
details, please refer next section.'''
 
 
==== Access via WebDAV protocol with SSL encryption (https://) ====
 
==== Access via WebDAV protocol with SSL encryption (https://) ====
 
 
Accessing SVN repository via WebDAV protocol with SSL encryption
 
Accessing SVN repository via WebDAV protocol with SSL encryption
 
(https://) is similar to http:// except you must install and configure
 
(https://) is similar to http:// except you must install and configure
 
the digital certificate in your Apache 2 web server.
 
the digital certificate in your Apache 2 web server.
 
 
You can install a digital certificate issued by Signing
 
You can install a digital certificate issued by Signing
 
authority like Verisign. Alternatively, you can install your own self
 
authority like Verisign. Alternatively, you can install your own self
 
signed certificate.
 
signed certificate.
 
 
This step assumes you have installed and configured digital certificate
 
This step assumes you have installed and configured digital certificate
 
in your Apache 2 web server. Now to access SVN repository please refer
 
in your Apache 2 web server. Now to access SVN repository please refer
 
the above section. You must use ''https://'' to access the SVN repository.
 
the above section. You must use ''https://'' to access the SVN repository.
 
 
==== Access via custom protocol (svn://) ====
 
==== Access via custom protocol (svn://) ====
 
 
Once the SVN repository is created, you can configure the access
 
Once the SVN repository is created, you can configure the access
 
control. You can edit /home/svn/myproject/conf/svnserve.conf file to
 
control. You can edit /home/svn/myproject/conf/svnserve.conf file to
 
configure the access control.
 
configure the access control.
 
 
For example, to setup authentication you can uncomment the following
 
For example, to setup authentication you can uncomment the following
 
lines in the configuration file:
 
lines in the configuration file:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
# [general]
 
# [general]
 
# password-db = passwd
 
# password-db = passwd
 
</nowiki></pre>
 
</nowiki></pre>
 
 
After uncommenting the above lines, you can maintain the user list in
 
After uncommenting the above lines, you can maintain the user list in
 
''passwd'' file. So, edit the file ''passwd'' in the same directory and
 
''passwd'' file. So, edit the file ''passwd'' in the same directory and
 
add new user. The syntax is as follows:
 
add new user. The syntax is as follows:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
username = password
 
username = password
 
</nowiki></pre>
 
</nowiki></pre>
 
 
For more details, please refer the file.
 
For more details, please refer the file.
 
 
Now, to access SVN via svn:// custom protocol either from the same
 
Now, to access SVN via svn:// custom protocol either from the same
 
machine or different machine, you can run svnserver using
 
machine or different machine, you can run svnserver using
 
''svnserve'' command. The syntax is as follows:
 
''svnserve'' command. The syntax is as follows:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
$ svnserve -d --foreground -r /home/svn
 
$ svnserve -d --foreground -r /home/svn
第269行: 第195行:
 
# --foreground -- run in foreground (useful for debugging)
 
# --foreground -- run in foreground (useful for debugging)
 
# -r -- root of directory to serve
 
# -r -- root of directory to serve
 
 
For more usage details, please refer,
 
For more usage details, please refer,
 
$ svnserve --help
 
$ svnserve --help
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Once you run this command, SVN starts listening on default port
 
Once you run this command, SVN starts listening on default port
 
(3690). To access the project repository, you must run the following command:
 
(3690). To access the project repository, you must run the following command:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
$ svn co svn://hostname/myproject myproject --username user_name
 
$ svn co svn://hostname/myproject myproject --username user_name
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Based on server configuration, it prompts for password. Once it is
 
Based on server configuration, it prompts for password. Once it is
 
authenticated, it checks out the code from SVN repository.
 
authenticated, it checks out the code from SVN repository.
 
 
To synchronize the project repository with the local copy, you can run
 
To synchronize the project repository with the local copy, you can run
 
update sub-command. The syntax is as follows:
 
update sub-command. The syntax is as follows:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
$ cd project_dir
 
$ cd project_dir
 
$ svn update
 
$ svn update
 
</nowiki></pre>
 
</nowiki></pre>
 
 
For more details about using each SVN sub-command, you can refer the
 
For more details about using each SVN sub-command, you can refer the
 
manual. For example, to learn more about co (checkout) command, please
 
manual. For example, to learn more about co (checkout) command, please
 
run:
 
run:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
$ svn co help
 
$ svn co help
 
</nowiki></pre>
 
</nowiki></pre>
 
 
==== Access via custom protocol with SSL encryption (svn+ssh://) ====
 
==== Access via custom protocol with SSL encryption (svn+ssh://) ====
 
 
The configuration and server process is same as svn:// method. For
 
The configuration and server process is same as svn:// method. For
 
details, please refer the above section. This step assumes, you have
 
details, please refer the above section. This step assumes, you have
 
followed the above step and run SVN server using ''svnserve'' command.
 
followed the above step and run SVN server using ''svnserve'' command.
 
 
It is also assumed that the ssh server is running in that machine and
 
It is also assumed that the ssh server is running in that machine and
 
it is allowing incoming connections. To confirm, please try to login to
 
it is allowing incoming connections. To confirm, please try to login to
第311行: 第226行:
 
perfect. If you cannot login, please address it before continuing
 
perfect. If you cannot login, please address it before continuing
 
further.
 
further.
 
 
svn+ssh:// protocol is used to access SVN repository using SSL
 
svn+ssh:// protocol is used to access SVN repository using SSL
 
encryption. As you know, the data transfer is encrypted. To
 
encryption. As you know, the data transfer is encrypted. To
 
access the project repository, you must run the following command:
 
access the project repository, you must run the following command:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
$ svn co svn+ssh://hostname/home/svn/myproject myproject --username user_name
 
$ svn co svn+ssh://hostname/home/svn/myproject myproject --username user_name
 
</nowiki></pre>
 
</nowiki></pre>
 
 
'''NOTE: You must use full path (/home/svn/myproject) to access SVN
 
'''NOTE: You must use full path (/home/svn/myproject) to access SVN
 
repository using this access method.'''
 
repository using this access method.'''
 
 
Based on server configuration, it prompts for password. You must
 
Based on server configuration, it prompts for password. You must
 
enter the password you use to login via ''ssh''. Once it is
 
enter the password you use to login via ''ssh''. Once it is
 
authenticated, it checks out the code from SVN repository.
 
authenticated, it checks out the code from SVN repository.
 
 
You can also refer the SVN book for details about svn+ssh:// protocol.
 
You can also refer the SVN book for details about svn+ssh:// protocol.
 
 
 
=== References ===
 
=== References ===
** [[UbuntuHelp:ApacheMySQLPHP|Setting up Apache on Ubuntu]]
+
* [[UbuntuHelp:ApacheMySQLPHP|Setting up Apache on Ubuntu]]
** [http://subversion.tigris.org/ SVN Home page]
+
* [http://subversion.tigris.org/ SVN Home page]
** [http://svnbook.red-bean.com/ SVN Book]
+
* [http://svnbook.red-bean.com/ SVN Book]
** [http://httpd.apache.org/docs/2.0/ Apache 2 Documentation]
+
* [http://httpd.apache.org/docs/2.0/ Apache 2 Documentation]
** [http://www.modssl.org/ Mod-SSL]
+
* [http://www.modssl.org/ Mod-SSL]
** [http://www.apache-ssl.org/ Apache-SSL]
+
* [http://www.apache-ssl.org/ Apache-SSL]
 
+
 
----
 
----
 
[[category:CategoryDocumentation]]
 
[[category:CategoryDocumentation]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 21:35的版本

This wiki document explains how to setup Subversion alias SVN on Ubuntu. The intended audience is experienced Linux users and system administrators.

Introduction

If you are new to Subversion, this section provides a quick introduction. Subversion is an open source version control system. Using Subversion, you can record the history of source files and documents. It manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to files and directories.

Assumptions

It is assumed that you are aware of how to run Linux commands, edit files, start/stop services in an Ubuntu system. It is also assumed that Ubuntu is running, you have sudo access and you want to use Subversion software. It is also assumed you have an internet connection.

Scope of this document

To make an SVN repository available to access using the HTTP protocol, you must install & configure web server. Apache 2 is proven to work with SVN. The installation of Apache 2 Webserver is beyond the scope of this document. However, the configuration of Apache 2 Webserver for SVN is covered in this document. To access an SVN repository using HTTPS protocol, you must install & configure digital certificate in your Apache 2 web server. The installation and configuration of digital certificate is beyond the scope of this document. (See forum/server/apache2/SSL.)

Installation

Subversion is already in the main repository. So, to install Subversion you can simply install the following packages subversion (see InstallingSoftware). If it fails reporting dependencies, please locate the packages and install them. If it reports any other issues, please resolve them. If you cannot resolve the issue, please refer the mailing list archive of those packages.

Server Configuration

This step assumes you have installed above mentioned packages on your system. This section explains how to create SVN repository and access the project.

Create SVN Repository

There are several typical places to put a Subversion repository; most common places are: srv/svn, /usr/local/svn and /home/svn. For clarity's sake, we'll assume we are putting the Subversion repository in /home/svn, and your project's name is simply 'myproject' There are also several common ways to set permissions on your repository. However, this area is the most common source of errors in installation, so we will cover it thoroughly. Typically, you should choose to create a new group called 'Subversion' that will own the repository directory. To do this (see [AddUsersHowto] for details):

  1. Choose System > Administration > Users and Groups from your Ubuntu menu.
  2. Select the Group tab
  3. Click the 'Add Group' button
  4. Name the group 'subversion'
  5. Add yourself and www-data (the Apache user) as users to this group
  6. Select 'OK' to commit your changes and exit the app.

You have to logout and login again before you are a member of the subversion group, and can do check ins. Now issue the following commands:

$ sudo mkdir /home/svn
$ cd /home/svn
$ sudo mkdir myproject
$ sudo chown -R www-data myproject
$ sudo chgrp -R subversion myproject
$ sudo chmod -R g+rws myproject

The last command sets gid for proper permissions on all new files added to your Subversion repository. The SVN repository can be created using the following command:

$ sudo svnadmin create /home/svn/myproject

If you want to use WebDAV as an access method described below, repeat the chmod -R g+rws myproject command again. This is because svnadmin will create directories and files without group write access. This is no problem for read only access or using the custom svn protocol but when Apache tries to commit changes to the repository linux will deny it access. Also the owner and group are set as root. This can be changed by repeating the chown and chgrp commands listed above.

Access Methods

Subversion repositories can be accessed (checkout) through many different methods-on local disk, or through various network protocols. A repository location, however, is always a URL. The table describes how different URL schemas map to the available access methods.

Schema Access Method
file:/// direct repository access (on local disk)
http:// Access via WebDAV protocol to Subversion-aware Apache 2 web server
https:// Same as http://, but with SSL encryption
svn:// Access via custom protocol to an svnserve server
svn+ssh:// Same as svn://, but through an SSH tunnel

In this section, we will see how to configure SVN for all these access methods. Here, we cover the basics. For more advanced usage details, you are always recommended to refer the svn book.

Direct repository access (file://)

This is the simplest of all access methods. It does not require any SVN server process to be running. This access method is used to access SVN from the same machine. The syntax is as follows:

$ svn co file:///home/svn/myproject
or
$ svn co file://localhost/home/svn/myproject

NOTE: Please note, if you do not specify the hostname, you must use three forward slashes (///). If you specify the hostname, you must use two forward slashes (//). The repository permission is depend on filesystem permission. If the user has read/write permission, he can checkout/commit the changes to the repository. If you set permissions as above, you can give new users the ability to checkout/commit by simply adding them to the Subversion group you added above.

Access via WebDAV protocol (http://)

To access the SVN repository via WebDAV protocol, you must configure your Apache 2 web server. First install the following package libapache2-svn (see InstallingSoftware). You must add the following snippet in your /etc/apache2/mods-available/dav_svn.conf file:

<Location /svn/myproject>
DAV svn
SVNPath /home/svn/myproject
AuthType Basic
AuthName "myproject subversion repository"
AuthUserFile /etc/subversion/passwd
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
</Location>

Alternatively, you can allow svn access on a per-site basis. This is done by adding the previous snippet into the desired site configuration file located in /etc/apache2/sites-available/ directory. Once you add the above lines, you must restart apache2 web server. To restart apache2 web server, you can run the following command:

sudo /etc/init.d/apache2 restart

Next, you must create /etc/subversion/passwd file. This file contains user authentication details. If you have just installed SVN, the passwd file will not yet exist and needs to be created using the "-c" switch. Adding any users after that should be done without the "-c" switch to avoid overwriting the passwd file. To add the first entry, ie.. to add the first user, you can run the following command:

sudo htpasswd -c /etc/subversion/passwd user_name

It prompts you to enter the password. Once you enter the password, the user is added. To add more users after that, you can run the following command:

sudo htpasswd /etc/subversion/passwd second_user_name

If you are uncertain whether the passwd file exists, running the command below will tell you whether the file already exists:

cat /etc/subversion/passwd

Now, to access the repository you can run the following command:

$ svn co http://hostname/svn/myproject myproject --username user_name

It prompts you to enter the password. You must enter the password configured using htpasswd2 command. Once it is authenticated the project is checked out. WARNING: The password is transmitted as plain text. If you are worried about password snooping, you are advised to use SSL encryption. For details, please refer next section.

Access via WebDAV protocol with SSL encryption (https://)

Accessing SVN repository via WebDAV protocol with SSL encryption (https://) is similar to http:// except you must install and configure the digital certificate in your Apache 2 web server. You can install a digital certificate issued by Signing authority like Verisign. Alternatively, you can install your own self signed certificate. This step assumes you have installed and configured digital certificate in your Apache 2 web server. Now to access SVN repository please refer the above section. You must use https:// to access the SVN repository.

Access via custom protocol (svn://)

Once the SVN repository is created, you can configure the access control. You can edit /home/svn/myproject/conf/svnserve.conf file to configure the access control. For example, to setup authentication you can uncomment the following lines in the configuration file:

# [general]
# password-db = passwd

After uncommenting the above lines, you can maintain the user list in passwd file. So, edit the file passwd in the same directory and add new user. The syntax is as follows:

username = password

For more details, please refer the file. Now, to access SVN via svn:// custom protocol either from the same machine or different machine, you can run svnserver using svnserve command. The syntax is as follows:

$ svnserve -d --foreground -r /home/svn
# -d -- daemon mode
# --foreground -- run in foreground (useful for debugging)
# -r -- root of directory to serve
For more usage details, please refer,
$ svnserve --help

Once you run this command, SVN starts listening on default port (3690). To access the project repository, you must run the following command:

$ svn co svn://hostname/myproject myproject --username user_name

Based on server configuration, it prompts for password. Once it is authenticated, it checks out the code from SVN repository. To synchronize the project repository with the local copy, you can run update sub-command. The syntax is as follows:

$ cd project_dir
$ svn update

For more details about using each SVN sub-command, you can refer the manual. For example, to learn more about co (checkout) command, please run:

$ svn co help

Access via custom protocol with SSL encryption (svn+ssh://)

The configuration and server process is same as svn:// method. For details, please refer the above section. This step assumes, you have followed the above step and run SVN server using svnserve command. It is also assumed that the ssh server is running in that machine and it is allowing incoming connections. To confirm, please try to login to that machine using ssh. If you can login, then everything is perfect. If you cannot login, please address it before continuing further. svn+ssh:// protocol is used to access SVN repository using SSL encryption. As you know, the data transfer is encrypted. To access the project repository, you must run the following command:

$ svn co svn+ssh://hostname/home/svn/myproject myproject --username user_name

NOTE: You must use full path (/home/svn/myproject) to access SVN repository using this access method. Based on server configuration, it prompts for password. You must enter the password you use to login via ssh. Once it is authenticated, it checks out the code from SVN repository. You can also refer the SVN book for details about svn+ssh:// protocol.

References