Creating An SVN Repository

For months, possibly years, I said I wanted to set up an SVN repository on our mediatemple (dv) 3.0 server. Well I finally installed SVN and trac. I wish I did a better job at documenting the actual install but I was a little inebriated at the time so the only documentation I have is a rather lengthing page or random commands and links to other sites. I will say that I used YUM package manager which made things a lot easier for a relatively inexperienced, and at the time inebriated, servadmin like myself.

After installing SVN and before creating your first repository it may be worth contemplating your server's repository structure. I know that I will be using the repository for school projects, personal projects and for work I do in the NICE Lab at Texas Tech. So after considering my options and reading some of the documentation in the "Repository Administration" handbook I finally settled on a schema.

I created a directory in /var/www/vhosts// called "repos". Within the directory I created three repositories (school, projects, NICE) using svnadmin.

I did this for a couple reasons, most of which are outlined in the previously mentioned document. If I created a single repository and just had several subfolders the revision number would change for the entire repository instead of a single project. If this happens the revision numbers may skip for a given project. This really isn't a big deal as it doesn't hurt anything, it just might drive me crazy though. I also used several repositories because it might make it easier to administer user permissions and custom hooks later down the road. Who knows, I may not really like this schema but only time will tell.

Supposedly we use 'fsfs' instead of Berkeley DB to avoid corruptions? I didn't investigate this too much as it seemed to be pretty common and directly used in the mediatemple knowledge base

  1. mkdir /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos
  2.  
  3. svnadmin create --fs-type fsfs /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name1>
  4. svnadmin create --fs-type fsfs /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name2>
  5. svnadmin create --fs-type fsfs /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name3>
  6.  
  7. chown -R apache_svn:psacln /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name1>
  8. chown -R apache_svn:psacln /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name2>
  9. chown -R apache_svn:psacln /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name3>

That's all there is to actually creating the repository but we really want to do more than just create a repository, we need it to be functional as well.

Change ownership of your new repositories so that apache can access them.

  1. chown -R apache:psacln /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name1>
  2. chown -R apache:psacln /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name2>
  3. chown -R apache:psacln /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name3>

Now we want to be able to access the virtual directory tree using our web browser so we need to edit the domain config file.

vi /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/conf/vhost.conf

Next, we need to set up some "rules" so that apache will know how to handle a situation when a user browses to a repository. To do this we add "location" parameters to the vhost.conf file.

  1. <location /<desired_url1>>
  2. DAV svn
  3. SVNPath /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name1>
  4. AuthType Basic
  5. AuthName "Subversion Repository 1"
  6. AuthUserFile /etc/svn-auth-file
  7. Require valid-user
  8. </location>
  9.  
  10. <location /<desired_url2>>
  11. DAV svn
  12. SVNPath /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name2>
  13. AuthType Basic
  14. AuthName "Subversion Repository 2"
  15. AuthUserFile /etc/svn-auth-file
  16. Require valid-user
  17. </location>
  18.  
  19. <location /<desired_url3>>
  20. DAV svn
  21. SVNPath /var/www/vhosts/<domain_name>/subdomains/<subdomain_name>/repos/<repository_name3>
  22. AuthType Basic
  23. AuthName "Subversion Repository 3"
  24. AuthUserFile /etc/svn-auth-file
  25. Require valid-user
  26. </location>

By using SVNParentPath instead of SVNPath we can reduce the three blocks down to just one.

  1. <location />
  2. DAV svn
  3. SVNParentPath /absolute/path/to/parent/folder
  4. AuthType Basic
  5. AuthName "Pare Technologies Subversion Repository"
  6. AuthUserFile /etc/svn-auth-file
  7. Require valid-user
  8. </location>

For more information about SVNParentPath and other apache directives see the "Basic Apache Configuration" section of the SVN handbook.

Using the above method, directives given for the parent repository are inherited by child repositories. By defining a new block with greater specificity than the parent block, more granular directives can be applied.

For example, I defined a parent path to be /
and arbitrarily set the AuthName directive in the block to something applicable to all the sub repositories. Say for example I wanted the AuthName to be something more specific to the sub-repository "project1".

  1. <location /project1>
  2. AuthName "Arbitrary Project 1 Suitable Text"
  3. </location>

The above code now has a higher specicifity than the parent block, as such when a user access svn.somesite.com/

In order for the above changes to take effect run the following...

/usr/local/psa/admin/sbin/websrvmng -a -v

Did you notice the line AuthUserFile /etc/svn-auth-file? I kind of skipped a step here. This line actually tells the server where it needs to find user information before granting access to the desired url.

To create a new user enter the following...

htpasswd -c /etc/svn-auth-file <user_name>

So I don't think this page is finished yet but I'm going to leave it live anyhow, maybe I will actually work on it...

Comments

Thanks for this

I'll likely be setting up an SVN repo in the near future, and strangely on a MediaTemple (dv) 3.0 server. hmm....
So your post is proving incredibly useful, thank you!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.