Wednesday, 23 May 2012

SVN server configuration on Linux step by step?

SVN server configuration on Linux step by step


Subversion Installation and configuration

check if subversion is installed or not

command rpm -qa | grep subverion

if not then install by yum command

command  yum install subversion

after installation create an directory where you want to configure projects reposatories

for exampel /home/subversion

command mkdir -p /home/subversion


to start the svn

command svnserv -d


to stop the svn

ps -aux | grep subversion

kill -9 <pid>
Creation of Project Using SVN (Subversion)

Creation of Project Using SVN (Subversion)

cd /home/subverion

svnadmin create <projectname> for example

svnadmin create test1


we can see test1 has been created in /home/subversion

cd test1/

there we can list list of files and folders

drwxr-xr-x 2 root root 4096 2010-04-06 10:36 conf
drwxr-xr-x 2 root root 4096 2008-11-08 00:19 dav
drwxr-xr-x 5 root root 4096 2009-08-13 11:28 db
-r--r--r-- 1 root root    2 2008-11-08 00:19 format
drwxr-xr-x 2 root root 4096 2008-11-08 00:19 hooks
drwxr-xr-x 2 root root 4096 2008-11-08 00:19 locks
-rw-r--r-- 1 root root  229 2008-11-08 00:19 README.txt


Conf


contains the configuratio file's like authz, passwd, svnserv.conf


       authz        : user authorization information
       passwd        : User password
       snvserv.conf    : main configuration for the project

db

Contains the list of verions that has been commetded by user's


after creation of project just enter in to conf folder say we have created test1 as project


cd /home/subversion/test1/conf

edit authz

[groups]
# harry_and_sally = harry,sally
admin = super.user
ycoregproject = svn.user1, svn.user2, svn.user3

[/]
@ycoregproject = rw    (where ycoregproject is an group name with read and write permission)
* =

[/]
@admin = rw             (Default admin who have read and write permission)
* =

[/beta]
@ycoregproject = r
* = r
[/version1.0]
@ycoregproject = r
* = r

save and close

edit passwd

super.user = sdfdsfdsf
svn.user1 = sfsdfsdf
svn.user2 = sfsdfs3fdef
svn.user3 = sdffdsf

save and quit

edit svnserve.conf

Orginal file

### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.  (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)

### Visit http://subversion.tigris.org/ for more information.

[general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
# anon-access = read
# auth-access = write
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
# password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file.  If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
# authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
# realm = My First Repository
[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### This section will be ignored if svnserve is not built with Cyrus
### SASL support; to check, run 'svnserve --version' and look for a line
### reading 'Cyrus SASL authentication is available.'
# use-sasl = true
### These options specify the desired strength of the security layer
### that you want SASL to provide. 0 means no encryption, 1 means
### integrity-checking only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128-bit
### encryption). The values below are the defaults.
# min-encryption = 0
# max-encryption = 256

modified file


### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.  (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)

### Visit http://subversion.tigris.org/ for more information.

[general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
anon-access = none
auth-access = write
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the conf directory.
### Uncomment the line below to use the default password file.
password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the conf
### directory.  If you don't specify an authz-db, no path-based access
### control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
# realm = My First Repository


********************************checkout of file from svn to live project directory*********************************

svn checkout file:///home/subverion/test1 /home/projects/test1.com

This we have to place in cron for every 1 minute.


to place in cron first

vi /bin/svnupdate-test1

set -x
svn checkout file:///home/svnrepository/test1 /home/projects/test1 > /tmp/cashforsvn.log
Counttest1=`cat /tmp/test1.log | wc -l`;
if [ "$Counttest1" -gt "1" ]
then
cat /tmp/cashtest1.log  | mail user1@ybrantlocal.com -cc user2@ybrantlocal.com user3@ybrantlocal.com  -s "test1 svn update details";
fi
echo " svn updated";


save and quit

chmod 700 /bin/svnupdate-test1

Note : make sure that for every svn you have included testing group id

crontab -e
*/1 * * * *  /bin/svnupdate-test1 >/dev/null 2>&1

save and quit

******************************************************************************************************************


****************************** information to Send mail for  individual users ********************************************


mysql details

db name :

db username :

db password :

svn.username :

svn.password

SVN URL : svn://server ip address/home/svnrepository/projectname

Phpmyadmin URL :""

******************************************************************************************************************


General Command

svn add <file name>
svn add *
svn commit -m “This is first file”
svn status
to remove files from svn
svn remove a aa
svn commit -m “”
svn checkout –revision 3 file:///home/subversion/xyz.com /home/project/ybrantdigital.com/
svn mkdir file:///home/subversion/xyz.com/rangarao/ -m “new dir”
svn copy file:///home/subversion/xyz.com file:////home/subversion

###############################################################################

Install SVN (Subversion) Server on Fedora 16/15/14/13, CentOS 6.2/6.1/6/5.8, Red Hat (RHEL) 6.2/6.1/6/5.8

1. Change root user

su -
## OR ##
sudo -i

2. Install needed packages (mod_dav_svn and subversion)

yum install mod_dav_svn subversion
Note: If you don’t have Apache installed already, this command installs it also. Read more about installing Apache and PHP >>

3. Modify Subversion config file /etc/httpd/conf.d/subversion.conf

Add following config to /etc/httpd/conf.d/subversion.conf file:
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule 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>
Read more SVN Access Control >>

4. Add SVN (Subversion) users

Use following command:
## Create testuser ##
htpasswd -cm /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.
Read more SVN Access Control >>

5. Create and configure SVN repository

mkdir /var/www/svn
cd /var/www/svn
 
svnadmin create testrepo
chown -R apache.apache testrepo
 
chcon -R -t httpd_sys_content_t /var/www/svn/testrepo
 
## Following enables commits over http ##
chcon -R -t httpd_sys_rw_content_t /var/www/svn/testrepo
Restart Apache:
/etc/init.d/httpd restart
## OR ##
service httpd restart
Goto http://localhost/svn/testrepo address and you should see something like following, write username and password:
SVN Subversion username and password
SVN testrepo revision 0:
SVN Subversion Repository Revision 0

6. Configure repository

To disable anonymous access and enable access control add following rows to testrepo/conf/svnserve.conf file:
## Disable anonymous access ##
anon-access = none
 
## Enable access control ##
authz-db = authz

7. Create trunk, branches and tags structure under testrepo

Create “template” directories with following command:
mkdir -p /tmp/svn-structure-template/{trunk,branches,tags}
Then import template to project repository using “svn import” command:
svn import -m 'Initial import' /tmp/svn-structure-template/ http://localhost/svn/testrepo/
Adding         /tmp/svn-structure-template/trunk
Adding         /tmp/svn-structure-template/branches
Adding         /tmp/svn-structure-template/tags
 
Committed revision 1.
Check results on browser and see testrepo revision 1:
SVN Subversion Repository Revision 1
Our forums user Will have also written guide, howto to install and configure SVN (Subversion). This is little bit different method.


###############################################################################

http://www.linuxunixworld.com/step-by-step-configuring-svn-server-in-linux

Step By Step Configuring SVN Server in Linux

July 7th, 2010 Posted in Linux

Subversion with apache on Linux (RHEL) box

  • First of all, install apache/httpd
yum install httpd
  • Make sure you apache is running. You can also type ‘http://localhost’ at your browser and apache test page should appear if your apache is running
/etc/rc.d/init.d/httpd start
OR
service httpd start

  • Make it start by default on startup
chkconfig httpd on
  • You not need to edit the apache configuration file for SVN server leave the default setting as it is
vi /etc/httpd/conf/httpd.conf
  • Install subversion and mod_dav_svn for apache
yum install mod_dav_svn subversion
  • Now you have to edit subversion.conf in /etc/httpd/conf.d/ As per your requirement
Here is my sample configuration file.

  • Now you have to create a “svnauth” file this file will contain users name and their passwords
htpasswd -cm /var/www/svnauth amitThis command was create a svnauth file and add amit as a user
htpasswd -m /var/www/svnauth root - Use this command to add another user like root


  • For user wise access permission on the repository you have to create new file here I created file with the name “svnuser”
vi /var/www/svnuser
• In the below file root user has read and write access on the whole repository but amit user has only read permission he will not able to make any changes on any files.
• You can also define repository folders permission to users wise here.
  • Create and Configure your repository
mkdir /var/www/svnhome – To be create folder named svnhome
cd /var/www/svnhome – change directory to the newly created
svnhome directory
svnadmin create repo – create SVN repository named repo
chown apache.apache -R repo – change ownership of ‘repo’ to apache
/etc/init.d/httpd restart – restart apache
Open you browser and type  http://localhost/repos Then first you have to login by previously created user by you .Now you can see that a page with ‘Revision 0:/’ will appear. Congratulation, you just completed the SVN server setup.
Trunk
Trunk is the main development area. This is where your next major release of the code lives, and generally has all the newest features.
Branches
Every time you release a major version, it gets a branch created. This allows you to do bug fixes and make a new release without having to release the newest – possibly unfinished or untested – features.
Tag
A tag is just a “snapshot” of a project in time. In Subversion each revision is a snapshot of the repository filesystem after each commit, and it can be used as a tag. But people often want to give some human-friendly names to tags, like release-1.0. Tag is a named snapshot, a symbolical connection with the specified revision of a project.

Tortoise SVN Client

Tortoise client software for client system you can download it from tortoise web site http://tortoisesvn.net/downloads
When first time you want to work on the project you have to create a local working copy. You can create working folder by just right and select SVN checkout from the menu.

In below screen short you can see here I want to create a new folder named My Project and click on Ok.

Now you need to provide your user name and password to get connected with your repository.


Now you can see a folder My Project with the green check it mean you’re working folder is ready and data fetched from repository server to your working folder.
When you create new file named Test file.txt in the working folder it show like this.

You should have to first update your SVN repository, for this you just have to right click and click on the SVN update option and then use SVN Commit…
Here you have to add some comment to that other users will know about this and press Ok.

It gave an error message because Amit user not has permission to add or modify on the repository. You have to use other user credential or ask permission for add or modify by system admin.

I used root user login credential and now it look like this

There is green check on the Test File.txt

Now I just add few words in that file and save and exit to it now you can see red check on the file it mean someone changed in the file and have to commit it so that your working file and repository file will be on same point.

Now it was at revision 7 and again green check on the file.
Let’s move on some other option like show log it will show you history of that file. Please review below screen short for more details.

Here you can compare any version changes.






http://wiki.centos.org/HowTos/Subversion

Subversion on CentOS


Subversion isn't just for coders and programmers...I know because I'm not one. I've begun to use it lately for many things, such as, backing up Nagios configurations, documents, and pretty much anything text based. I don't know why I didn't start using it sooner, but none the less, here I am. This document quickly explains how to install, configure, and use subversion locally, as well as across Apache on a network. For complete and complex configurations and installations seek the documentation provided. There is plenty of well written documentation on the subject, that far exceeds my knowlegde of the tool. This just helps get you started quickly, for those like me that just like to jump in head first into new things.

1. System


CentOS 4.x/RHEL 4
CentOS 5.1/RHEL 5

2. References


Subversion: http://subversion.tigris.org/
Version Control with Subversion: http://svnbook.red-bean.com/

3. Installation


[root@lucifer ~]# yum install mod_dav_svn subversion


The first thing to do is to install the packages I mentioned above. If you don't have Apache installed already, it'll go ahead and drag that down as well.
When you install from yum, there's a longer list than the two packages above that will automatically resolve themselves. Some other things will be installed automatically. Depending on your packages, your mileage may vary.

4. Configurations


4.1. Apache


Before you delve into the deep end, you need to ensure Apache is set up first. I'm assuming this is a virgin installation, so if you already have Apache things going...be careful what you change. I'm also going to explain setting this up with basic password protection. You can easily let this out, however, if you want to allow access to the repos from everyone.
First thing is make sure you open up /etc/httpd/conf/httpd.conf and at least change the ServerName directive. If you need more help or more complex configurations, then consult the Apache docs please.
[root@lucifer ~] vim /etc/httpd/conf/httpd.conf -- Edit what you need and save the file
[root@lucifer ~] service httpd start
[root@lucifer ~] chkconfig httpd on


Browse to your machine on the network and see if you get your test page, which you should: http://yourmachine. Working? Great, let's move along to more fun things.

4.2. Subversion's Apache configs


The next step is to setup some settings within Apache so Subversion and Apache play nice together. Get yourself to the example configuration file Subversion installed for you.
[root@lucifer ~] cd /etc/httpd/conf.d/
[root@lucifer ~] vim subversion.conf

# Make sure you uncomment the following if they are commented out
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

# Add the following to allow a basic authentication and point Apache to where the actual
# repository resides.
&lt;Location /repos&gt;
        DAV svn
        SVNPath /var/www/svn/repos
        AuthType Basic
        AuthName "Subversion repos"
        AuthUserFile /etc/svn-auth-conf
        Require valid-user
&lt;/Location&gt;


The location is what Apache will pass in the URL bar. For instance: http://yourmachine/repos points to the SVNPath that you have specified. My examples are just that, so feel free to put things where you want. Make sure you save the file when you are finished editing.
Next we have to actually create the password file that you specified in the previous step. Initially you'll use the -cm arguments. This creates the file and also encrypts the password with MD5. If you need to add users make sure you simply use the -m flag, and not the -c after the initial creation.
[root@lucifer ~] htpasswd -cm /etc/svn-auth-conf yourusername
New password:
Re-type new password:
Adding password for user yourusername
[root@lucifer ~] htpasswd -m /etc/svn-auth-conf anotherusername
New password:
Re-type new password:
Adding password for user anotherusername


4.3. Configure your repository


The next thing you need to do is to create the actual repository from which you will check in and out your files. This is simple to do with some of the included svn tools.
[root@lucifer ~] cd /var/www/ -- Or wherever you placed your path above
[root@lucifer ~] mkdir svn
[root@lucifer ~] cd svn
[root@lucifer ~] svnadmin create repos
[root@lucifer ~] chown -R apache.apache repos
[root@lucifer ~] service httpd restart


Go test out whether or not you can access your repository from a web browser: http://yourmachine/repos. You should get a popup box asking for a username and password. If so, type in your credentials and you should be displayed with a Revision 0:/ page. If so, that's it for setting up a repo. If you want multiple repos, check out the docs from the links provides above. This sets up one repository and shows you how to start using them. Speaking of, let's move on to just that.

5. Using Subversion


5.1. Layout Your Repo


For instance:
.
|-- project1
|   |-- branches
|   |-- tags
|   `-- trunk
`-- project2
    |-- branches
    |-- tags
    `-- trunk


The book explains why in a bit more detail, and I mainly don't bother using this type of layout...because I'm not doing coding and maintaining "projects" per se.
As an example, I'm going to just create some dummy directories and throw some files in them. This is from the actual SVN server. Play along.

[root@svnser ~] cd /tmp
[root@svnser ~] mkdir mytestproj
[root@svnser ~] cd mytestproj
[root@svnser ~] mkdir configurations options main
[root@svnser ~] vim configurations/testconf1.cfg -- Add whatever you want to these files.
[root@svnser ~] vim options/testopts1.cfg
[root@svnser ~] vim main/mainfile1.cfg


Keep in mind that you can layout anything anyway you'd like. Once you have the initial layout of what you want, let's go ahead and import this up to Subversion.

5.2. Importing


[root@svnser ~] svn import /tmp/mytestproj/ file:///var/www/svn/repos/mytestproj -m "Initial repository layout for mytestproj"
Adding         /tmp/mytestproj/main
Adding         /tmp/mytestproj/main/mainfile1.cfg
Adding         /tmp/mytestproj/configurations
Adding         /tmp/mytestproj/configurations/testconf1.cfg
Adding         /tmp/mytestproj/options
Adding         /tmp/mytestproj/options/testopts1.cfg


5.3. Checking Out


Now, just to check it out across the web browser: http://yourmachine/repos. You'll get whatever you have imported showing up to peruse. Once you upload your original layout from the local SVN server, you're now free to use it remotely on another machine. As long as you are connecting to the Subversion server with the user account(s) that you created earlier. Let's give it a shot.
[me@mylappy ~] cd /tmp
[me@mylappy ~] svn co http://yoursvnserver/repos/mytestproj
Authentication realm: &lt;http://yoursvnserver:80&gt; Subversion repos
Password for 'youruser':
A    mytestproj/main
A    mytestproj/main/mainfile1.cfg
A    mytestproj/configurations
A    mytestproj/configurations/testconf1.cfg
A    mytestproj/options
A    mytestproj/options/testopts1.cfg
Checked out revision 1.


5.4. Edit &amp; Commit


As you can see, you've checked out revision 1 from the Subversion server. Now you can edit some things and commit the changes back to the Subversion server.
[me@mylappy ~] cd mytestproj
[me@mylappy ~] vim configurations/testconf1.cfg -- Add or delete something and save.
[me@mylappy ~] svn commit -m "Added a line to testconf1.cfg."
Sending        configurations/testconf1.cfg
Transmitting file data .
Committed revision 2.


The nice thing about this then, is that you can delete all of the directories that you just checked out on your machine. The only reason you checked them out, was to edit them, and then send them back up the line. Web browse to your server to check out the different files.

5.5. Adding/Deleting Items


Now this is all fine and dandy, but how do you add more files to an already existing repo directory? Easy, with the add argument. Go ahead and checkout your latest and greatest, copy a file over to a directory, add, then commit the changes.
[me@mylappy ~] svn co http://yoursvnserver/repos/mytestproj
A    mytestproj/main
A    mytestproj/main/mainfile1.cfg
A    mytestproj/configurations
A    mytestproj/configurations/testconf1.cfg
A    mytestproj/options
A    mytestproj/options/testopts1.cfg
Checked out revision 2.

[me@mylappy ~] cd mytestproj
[me@mylappy ~] cp /etc/yum.repos.d/CentOS-Base.repo configurations/
[me@mylappy ~] svn add configurations/CentOS-Base.repo
A         configurations/CentOS-Base.repo

[me@mylappy ~] svn commit -m "Added the CentOS Yum repo file."
Adding         configurations/CentOS-Base.repo
Transmitting file data .
Committed revision 3.


To delete items simply use delete instead of add. Commit your changes back up, and you're good to go. It's as simple as that. Go back over to your web browser again and you'll notice the revision number should say 3. You'll be able to click through the files to pick our your differences as well.

5.6. Reverting Back


Ok, this is all great but how do I revert back to an older revision...isn't this the point of Subversion? Yep, it's easy. If you're not sure as to what revision you're at...check out the log command. This is why you put a message in every commit. Short and to the point, but enough information to ring a bell that you perhaps forgot about.
[me@mylappy ~] svn log http://yoursvnserver/repos -- For the entire repository
[me@mylappy ~] svn log http://yoursvnserver/repos/mytestproj -- For the specific project


You'll get a nice complete list of revision numbers along with the comments, like I mentioned above. This allows you to pick which revision you want to check back out now.
[me@mylappy ~] svn co -r 1 http://yoursvnserver/repos/mytestproj


This command will drag down revision number 1.

6. Access control lists


Usually, you don't want to give every user access to every repository. You can restrict repository access per user by using ACLs. ACLs can be enabled with the AuthzSVNAccessFile file option, which takes a file name as its parameter. For instance:
AuthzSVNAccessFile /etc/svn-acl-conf

You can add this to the relevant Location section:
<Location /repos>
        DAV svn
        SVNParentPath /var/www/svn/repos
        AuthzSVNAccessFile /etc/svn-acl-conf
        AuthType Basic
        AuthName "Subversion repos"
        AuthUserFile /etc/svn-auth-conf
        Require valid-user
</Location>

You can then create /etc/svn-acl-conf. This file consist of sections of the following form:
[reponame:repopath]
user = access

Where access can be r (read), rw (read-write), or empty (no access at all). The default ACL is to give users no access to a repository. Suppose that there is a repository named framework to which you would like to give john read access, and joe read and write access. You could then add the following section:
[framework:/]
john =  r
joe = rw

It is also possible to create groups in a section named groups, groups are then prefixed with the 'at' sign (@) in the access control lists. For instance:
[groups]
staff = joe, george

[framework:/]
john =  r
@staff = rw

If you would like to make all repositories readable to all users, you can add a section for the root directory of every repository:
[/]
* = r

7. Afterthought


This is only a very very small part of the power of what Subversion can offer you. This quick guide will get you going, and show you how to use it a bit to understand how it's working. You can do all kinds of things with the Subversion tools, so make sure you check the docs out to learn about different options that might assist you in your tasks. Also remember that the Apache installation might be overkill for your needs. You can completely use the Subversion tools locally on a machine by specifying file:///path/to/repo, instead of my examples across Apache as http://yoursvnserver/repos/whatever. From what I read, many folks use it on their local boxes just to keep their minds straight for huge projects and configurations file. Good luck

8. Further reading

Version Control with Subversion

No comments:

Post a Comment