How to Set up a Linux Server with Subversion and Trac

| 11 Comments | No TrackBacks

I've been spoiled lately - all of the contract projects I've been involved with have used Trac and Subversion. I wanted the same killer set up for my hobby projects at home, so I put together a Linux server and documented the steps along the way to share with you.

First, it's always a good idea to use version control. I used to have Subversion installed locally on my Windows machine so I could keep track of changes, revert if I did something stupid, and have backups in the event I lost everything. Subversion has saved me a lot of time on multiple occasions, and to me it's a no-brain decision to use it.

The very first time I saw Trac, I loved it. Trac features an integrated wiki, bug base, and integrates tightly with Subversion. You can have a look at the Timeline to see what has changed across your project and when, look at the changes that were applied between revisions with the integrated diff view, link a bug to a particular revision (say, bug #9 was fixed in change set #104), use the wiki to describe a change set in more detail, etc. Trac is a very easy to use system that helps keeps projects organized, and gives you the ability to look inside of a project to see how it's progressing.

For my personal projects, I thought Trac would be overkill at first since I'm really a one-man team at home, but it's really been nice to have. The biggest change has been keeping my desk free of clutter. Instead of littering my desk with yellow post-it notes for ideas, bugs, features, etc., I just put all of that into the Trac project. Once you use it, you can't live without it.

Introductions aside, it's time to get down to business. First, I'm really not a Linux expert. All of what I know about Linux was gathered from using it in college to get my Comp. Sci. degree. I'd use it at home more, but I'm a Flash/Flex developer.. so there you go. Take this with a grain of salt - I believe these instructions will be useful, but there's no guarantee they'll actually work for you (I may have tinkered with something and forgot to make note of it). In any event, a standard disclaimer applies: The following information is to be used at your own risk. You agree not to hold me responsible if anything bad should happen as a result of following these instructions, including, but not limited to, an invasion of lemmings attacking a small army of ants that happen to crawl up your pants leg while trying to power off your newly configured Linux server due to a massive lightning strike off the coast of Kanagawa. Wow, I really need to cut down on the coffee in the afternoon.

Here goes...

  • Find yourself a computer to use. I have an older desktop not being used anymore that I was able to turn into a server on my home network. If you don't have a computer lying around, I recommend using virtualization software, such as VMware Workstation. It costs a bit of money, but I've had good experience with it in the past.
  • Download and install OpenSuse 10.0. Really, you can use any Linux disto, but this guide was written assuming that your using SuSE. This is the distro I'm most comfortable with (I've been using it off and of since version 6.4).
  • On the Installation Settings page, change the software options.
    • From the selections on the left, pick...
      • Simple Webserver with Apache2
      • C/C++ Compiler and Tools
    • Additionally, search for the following packages to make sure the get installed too:
      • python
      • python-devel
      • python-sqlite
      • python-xml
      • pyxml
      • apache2
      • apache2-mod-python
      • apache2-prefork
      • libapr0
      • subversion-python
      • subversion
      • subversion-tools
      • swig
  • After installation is complete, download and install docutils. I used the snapshot version from the website. Extract the file to a temporary location, switch to root by using the "su root" command in a terminal window, and then run "./install.py" to install.
  • Download ClearSilver 10.2 or later. Extract to a temporary location. Run the following commands (as the root user) from the directory you extracted the files to:
    • ./configure --prefix=/usr --mandir=/usr/share/man --disable-java --disable-ruby --disable-csharp --enable-gettext --disable-apache --with-python=/usr/bin/python --disable-perl
    • make
    • make install
    • ldconfig
  • After installing ClearSilver, copy the neo_cgi.so file from the python directory (under the clearsilver temporary directory) to /usr/lib/python/site-packages/ directory.
    • cp python/neo_cgi.so /usr/lib/python/site-packages/
  • Create a new user and group to run the server for the repository. As root user, run:
    • groupadd svn
    • useradd -m -d /srv/svn/ -g svn svn
  • Create a repository. I'll use "sample" as the name here. Switch to the svn user first:
    • su - svn
    • mkdir /srv/svn/repositories
    • mkdir /srv/svn/repositories/sample
    • svnadmin create /srv/svn/repositories/sample
  • Download Trac from the website. Install Trac by extracting it and then running the following command (as the root user again):
    • python setup.py install
  • Run the following commands to set up an environment and add your "sample" project to it, switching to the svn user first:
    • su - svn
    • mkdir /srv/svn/tracenv
    • trac-admin /srv/svn/tracenv/sample/ initenv
  • After running trac-admin you'll have to answer a series of questions. Enter the project name, use the default connection string for the database, use /srv/svn/repositories/sample as the repository location, and use the default location for the templates.
  • Now the repository and Trac project is set up. All we need to do is hook up apache to serve everything....
    • I'd love to know how to do this. I don't have experience with using apache (all of my experience is with IIS). If you can provide information on how to set up the .conf files, create user accounts, grant users access to certain projects, and run everything over https... that would be a great addition here!
  • Because I'm not an apache whiz, I've had to use the built in server for both Subversion and Trac since I've had trouble trying to integrate everything. It's pretty easy to get Subversion and Trac working on their own though:
    • As the svn user, run the following command to start the Subversion server:
      • svnserve -t -r /srv/svn/repositories
    • Whichever users you want to allow to connect to the repository, make sure to add them as part of the svn group. In my case, I added my "darron" account to the svn group, and now I'm able to connect to my repositories with the following connection string (changing your username and host as necessary):
      • svn+ssh://darron@192.168.1.105/srv/svn/repositories
    • As the svn user, run the following command to serve trac:
      • tracd --port 8000 /srv/svn/tracenv/project1 /srv/svn/tracenv/project2 (..etc)
    • Now, to view the Trac pages for my projects, I just connect to http://192.168.1.105:8000 and everything works great.
    • Oh, somewhere along the way you might need to change the permissions so that the svn user can make changes to both Subversion and Trac. As the root user, run these commands after setting up a new repository and Trac project:
      • chmod -R g+w /srv/svn/repositories/sample/db
      • chmod -R g+w /srv/svn/tracenv/sample/db

Clear as mud, right? The process really isn't as painful as it sounds, though I think I assume at least a little bit of Linux experience. Also, as I said, I'm not an expert at configuring apache. Ideally, both Subversion and Trac would be served by apache, and there would be a way to control access to individual projects. I'm hoping someone reading this knows more about apache than I do (very likely), and that they'll be able to fill in that part for me.

Hopefully these instructions work for you. I've tried to capture everything I did to set up my Linux server... and since it works for me, well, hopefully you'll see the same results. If you run into trouble, I'll do my best to help out... but again, this is really the first time I've ever played with setting up a Linux server.

If you're looking for more information on the internet, I've found the following links helpful:

Good luck!

No TrackBacks

TrackBack URL: http://www.darronschall.com/mt/mt-tb.cgi/84

11 Comments

I love Subversion and Trac too! I'm no Linux Whiz, so I chose to go with http://www.cvsdude.org/. They offer a free account for testing and it's not too pricey for the options either. Saves me a lot of headaches and time.

I also use the TortoiseSVN Client. It integrates really nicely into the Explorer interface, so you just right-click to Commit a file :)

J

I saw that SourceSecure was merged with CVSDude... I'm more comfortable running my own server locally, to be honest. To each his own. :-)

I use a combination of TortoiseSVN, Subclipse, and AnkhSVN for my development. Works great!

Nice tutorial. I just setup a subversion+trac server for a client. I was a Centos distro so most of the work was done via yum :p

I preffered using an apache server instead of the built-in trac webserver. BTW, this reminds me i need to try lighttpd. I've heard great things about it.

Thanks for the tuto! :)

Ah yes. Hey did you post this to Trac's site. They always need this type of stuff. Could do Apache? Why didn't you ask could have given you the config files and you would be all done. Also on Windows version I believe Clearsilver does not need to be installed.

Boy, couldn't setup Apache, lol.

Ah Kev, give me a break - when we worked at NC together you were the one that handled setting up Apache. It's not in my domain of expertise, so even simple tasks like setting up users and granting access to only certain projects and such is slightly beyond me. Like I said, in the past I've always dealt with IIS, and I don't have much experience in configuring Linux servers. :-)

Hi Darron,

I was thinking in change CVS system at work to SVN, but as we are using mainly Eclipse to interface CVS I'd like to know if the SVN Eclipse plugin is mature enough to work with. please could you post a comment about it? is Subeclipse stable?

Many thanks for the post :)

Hi Carlos,

I've been using Subclipse for a long time without issue. I would say it's very stable. As a backup, just in case, I also have TortoiseSVN installed. Between the two of them you won't have any problems.

Thanks for the tutorial. before I found this I had an old P3 running gentoo linux and subversion but was having trouble configuring a few things. Again thanks for the help

Crystal clear!
Well done, Darron, it saved me a lot of time. Thanks.

to make this apache2 ready, here are the working steps, basically this is exact the same as /usr/share/doc/packages/subversion/README.SuSE

this is done on suse 10.0 (eval DVD)

1. download needed
download subversion-server from ftp://chuck.ucs.indiana.edu/pub/array2/linux/opensuse/distribution/SL-10.0-OSS/inst-source/suse/x86_64/subversion-server-1.2.3-2.x86_64.rpm

2. install subversion_server
rpm -Uvh subversion-server

3. config
vi /etc/sysconfig/apache2
then add 'dav dav_svn' to setting $APACHE_MODULES

To load the configuration for a certain
virtual host, add
Include /etc/apache2/conf.d/subversion.conf
or
Include /path/to/your_subversion_configuration
in the respective virtual host configuration. This *may* be done in the default
virtual host (/etc/apache2/default-server.conf).

Add the http repository data to /etc/apache2/conf.d/subversion.conf:
#------------------------------------------------------------------------
#
# project related HTML files
#

Alias /repos "/home/svn/html"


Options +Indexes +Multiviews -FollowSymLinks
IndexOptions FancyIndexing \
ScanHTMLTitles \
NameWidth=* \
DescriptionWidth=* \
SuppressLastModified \
SuppressSize

order allow,deny
allow from all

# project repository files for project1

DAV svn
SVNPath /home/svn/repos/project1

# Limit write access to certain people
AuthType Basic
AuthName "Authorization for project1 required"
AuthUserFile /home/svn/user_access/project1_passwdfile
AuthGroupFile /home/svn/user_access/project1_groupfile

Require group project1_committers

# Limit read access to certain people

Require group project1_committers
Require group project1_readers

# project repository files for project2

DAV svn
SVNPath /home/svn/repos/project2

# Limit write permission to list of valid users.

# Require SSL connection for password protection.
# SSLRequireSSL

AuthType Basic
AuthName "Authorization for project2 required"
AuthUserFile /home/svn/user_access/project2_passwdfile
Require valid-user

#------------------------------------------------------------------------


rcapache2 restart
or
/etc/init.d/apache2 restart


4. user and filesystem
groupadd svn
useradd svn -G svn

create a few directories:
mkdir -p /home/svn/repos
mkdir -p /home/svn/user_access
mkdir -p /home/svn/html


# to create the repositories itself:
cd /home/svn/repos
svnadmin create project1
chown -R wwwrun:www project1/{dav,db,locks}
svnadmin create project2
chown -R wwwrun:www project2/{dav,db,locks}


# Now create the user access files:
# project1 is a restricted project. read access requires a password. write access is limited to a few users
touch /home/svn/user_access/project1_passwdfile
chown root:www /home/svn/user_access/project1_passwdfile
chmod 640 /home/svn/user_access/project1_passwdfile

htpasswd2 /home/svn/user_access/project1_passwdfile olaf
htpasswd2 /home/svn/user_access/project1_passwdfile olh

# this is the group file for project1:
/home/svn/user_access/project1_groupfile
# content:
project1_committers: olh
project1_readers: olaf olh

# project2 is world readable, but only a few can commit to the sources.
touch /home/svn/user_access/project2_passwdfile
chown root:www /home/svn/user_access/project2_passwdfile
chmod 640 /home/svn/user_access/project2_passwdfile
htpasswd2 /home/svn/user_access/project2_passwdfile olaf

# Now import the data, e.g.
svn import /path/to/project1-tree http://host/repos/project1
svn import /path/to/project2-tree http://host/repos/project2

5 test and done
# You should be able to connect to the server:
http://host/repos/project2
http://host/repos/project1

Great.

htpasswd2: command not found

This is frustrating.

Leave a comment



About this Entry

This page contains a single entry by darron published on January 23, 2006 3:00 PM.

Getting Friendly with Eclipse Workspaces was the previous entry in this blog.

Spanky Makes the Rounds is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Archives

OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.02