您的位置:首页 > 其它

Setup SVN server on Ubuntu 14.04

2016-07-12 14:10 453 查看
https://www.howtoforge.com/how-to-install-and-use-svn-with-apache-dav_svn-on-ubuntu-14.04
http://www.if-not-true-then-false.com/2010/svn-subversion-access-control-with-apache-and-mod-authz-svn/


1.1 SVN-An Overview

Subversion is a popular open source version control system that enables users to record the history of source files and documents, and manage
files and directories over a period of time. It is akin to a tree of files being placed into a central repository on the lines of a regular file server, barring that each modification made to these files and directories is always remembered.


1.2 Step-by-Step Guide on the Installation and Use of SVN on Ubuntu 14.04

This tutorial explains the process of installing and using SVN on Ubuntu 14.04 as per steps outlined below.


1.2.1 Step 1: Ensuring Up-to-Date Installed Packages

At the outset, you must ensure that all the packages installed on your system are updated. The following command shall help you do that:

sudo apt-get update


1.2.2 Step 2: Downloading the Subversion, Subversion Tools and Libapache2 packages

To run a Subversion (SVN) server, you need all the requisite packages, and you need to key in the following command for the same:

sudo apt-get install subversion subversion-tools libapache2-svn
You are now geared up to for the next step.



1.2.3 Step 3: Creating Subversion (SVN) Directory

Here, you are required to create a directory where all the repositories may be housed. It is advisable to choose a directory that is easily
accessible to your the managed backup service for obvious reasons. Please key in the following command to do the same:

sudo mkdir /home/svn
This brings you to the end of this step, and you may move on to the next one, as explained below.


1.2.4 Step 4: Creating a Test Repository

As part of this step, users need to first create a new folder to create the test project, and subsequently create a repository for the same.
The following command shall help you do that:

sudo mkdir ~/test

sudo svnadmin create /home/svn/test -m 'initial project structure'
The aforementioned command shall create a new repository for you that would comprise the base file structure. You may now graduate to the next
step.


1.2.5 Step 5: Adding Files into the Test Project

Once you have created the repository, please use the following command to add files into the test project:

cd ~/test

mkdir trunk tags branches
You are now ready to import these new directories into the test repository, using the following command:

sudo svn import ~/test file:///home/svn/test -m 'Initial project directories'
The above command lets you add and also commit the new directories into the repository, all in one go. Further, for Apache to access the SVN
repositories, the directory thus created (/home/svn directory) must necessarily be owned by the same user and also group that Apache runs as. More often than not, in Ubuntu, it happens to be www-data.
In order to change the directory owner, please use the following command:

sudo chown -R www-data:www-data /home/svn
The above command shall enable you to change the owner of the directory, and you may subsequently move on to the next step.


1.2.6 Step 6: Configuration of Apache

Using the following command, you would be able to enable the dav_svn
Apache module:

sudo a2enmod dav_svn
After having enabled this, you would be required to modify the Apache configuration file (as follows):

sudo nano /etc/apache2/apache2.conf
Right at the bottom of the file, please add the following lines, before saving the file by hitting Ctrl+X.
DAV svn
SVNParentPath /home/svn

After having saved this, you must restart the Apache service so as to implement the changes, by using the following command:

sudo service apache2 restart

Moving on, you would now be in a position to browse through the test repository you created by opening the web browser in Firefox, and visiting
the following link:
http://127.0.0.1/svn/test.
Here, you would be able to view all the three directories, though they would all be empty. You may now proceed to the next step.


1.2.7 Step 7: Securing the SVN Repositories

Before the users start committing the files to the test repository, they must ensure that only authorized users are able to view it. The current
settings, however, would allow unauthorized viewing, and checking out of the repository and its contents, in addition to checkout and committing of files by just about anyone. To secure the repositories, you must supply a username and a password before you
begin to view the repository/ perform any action on the same. To execute this, you must reopen apache2.conf,
and replace the SVN Location information with the following:
DAV svn
SVNParentPath /home/svnAuthType Basic
AuthName "My SVN Repositories"
AuthUserFile /etc/svn-auth
Require valid-user

Further, you must create a password file by using the following command:

htpasswd -cm /etc/svn-auth disney
Upon keying in the above command, you would be prompted to enter and confirm your password, and subsequently your details would be saved. Next,
the Apache service must be restarted, and subsequently, the user would need to authenticate themselves before going about viewing the repositories.


1.2.8 Step 8: Checking Out the Repository and Committing Files

For checking out the files contained within the repository into a new directory (let us call it Test2) within the home directory, you first
need to create the new directory before you may issue the checkout command (as explained below):

cd ~

mkdir test2

svn checkout http://127.0.0.1/svn/test/trunk test2
You may now start adding files into the directory. Once the files have been created, you must perform the SVN add command, and pass in individual
filenames as further arguments (as given below):

svn add index.php

svn add *
Once all the required files have been added, these may be committed using svn
commit -m 'commit message' , and further, the server may be updated using the SVN up command. This brings you to the end of the process!


Setup SVN (Subversion) Access Control with Apache and mod_authz_svn


1. Change root user

Shell

01234su -## OR ##sudo -i

2. Add SVN (Subversion) users

Use following command:Shell

0

1

2

3

4

5

6

7

8

9

10

11

12

##
Create testuser ##

htpasswd
-c
-m
/etc/svn-auth-users
testuser

New
password:

Re-type
new
password:

Adding
password
for
user
testuser

##
Create testuser2 ##

htpasswd
-m
/etc/svn-auth-users
testuser2

New
password:

Re-type
new
password:

Adding
password
for
user
testuser2

Note: Use exactly same file and path name as used on subversion.conf file.
This example use /etc/svn-auth-users file.


3. Create SVN Access Control file

On this guide, I use following /etc/svn-access-control file.

Shell

0123## Open /etc/svn-access-control file with your favourite editor ##nano -w /etc/svn-access-control
Add following type content to file:Shell

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

[groups]

testgroup
=
testuser1,
testuser2

testgroup2
=
testuser3,
testuser4,
testuser5

testgroup3
=
testuser6,
testuser7

[/]

*
=
r

@testgroup
=
rw

testuser4
=
rw

[testrepo:/]

@testgroup2
=
rw

testuser6
=
rw

[testrepo2:/trunk]

@testgroup3
=
rw

testuser5
=
rw

[testrepo2:/tags]

@testgroup3
=
r

testuser5
=
rw


4. Add AuthzSVNAccessFile to subversion server config

Previously created /etc/httpd/conf.d/subversion.conf file:

Shell

0123456789101112LoadModule dav_svn_module modules/mod_dav_svn.soLoadModule authz_svn_module modules/mod_authz_svn.so <Location /svn> DAV svn SVNParentPath /var/www/svn AuthType Basic AuthName "Subversion repositories" AuthUserFile /etc/svn-auth-users Require valid-user</Location>
Add AuthzSVNAccessFile row to config:Shell

0

1

2

AuthzSVNAccessFile
/etc/svn-access-control

Finally /etc/httpd/conf.d/subversion.conf file should look something like following:

Shell

012345678910111213LoadModule dav_svn_module modules/mod_dav_svn.soLoadModule authz_svn_module modules/mod_authz_svn.so <Location /svn> DAV svn SVNParentPath /var/www/svn AuthType Basic AuthName "Subversion repositories" AuthUserFile /etc/svn-auth-users AuthzSVNAccessFile /etc/svn-access-control Require valid-user</Location>

5. Restart Apache Web Server

Shell

0

1

2

3

4

/etc/init.d/httpd
restart

##
OR ##

service
httpd
restart

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: