Installing Subversion and Trac on a Shared Server

I spent some time over the last week or so setting up Subversion 1.5.5 and Trac 0.11.1 on my hosted site on a shared linux server. It was a bit tricky and most of the posts I’ve found thus far are a bit out of date, so I thought I’d write one up in case it saves anyone some time.
It’s all working now, but there were definitely a few things that tripped me up along the way. These directions are specific to my hosting service, but much of it may be applicable to other services. Often there is more than one way to do things and you’ll find other methods on other sites. This is just what worked for me. This looks like alot of work, but once I figured it all out, I was able to reinstall everything in about half an hour.
Prerequisites:
- You need to know how to use Putty or a similar tool to access your account via ssh. Note that with Putty, you can copy text from your desktop and paste it into Putty by right-clicking at the prompt. That will save you on typing.
- Pay careful attention to the directions on using subversion clients to access your subversion repositories with svnserve. Trying to access new subversion repositories with old svnserve installations seems to lock things up for a bit with format exceptions.
- If you’re a windows user like I am, avoid editing files on your desktop and then copying them up to the site unless your editor is unix friendly. The line endings requirements for linux and some windows programs are different and this can cause problems.
- Back things up and proceed at your own risk. These directions worked for me, but I can’t guarantee or take responsibility for your results.
Getting Started:
First, log into your site using Putty and execute the pwd command to get the path to your home directory. Write down your actual value and substitute it below whereever you see {path to your home}.
Create a database:
If you are going to use MySql like I have, create a new MySql database for your trac project using your hosting companies’ database creation interface. Write down the database name, user name, password, and host. You’ll use this information later to create the database connection string for the trac project. If you’d prefer to use sqlite, follow the sqlite directions here: Natmaster.com
Setup the folder structure:
I used this post at Natmaster.com extensively as a resource and liked the folder structure. This will keep all of the installation files together so they can be deleted easily at the end. It installs all of your programs into the packages directory under your home folder and your trac sites into the trac_sites directory for easy backups.
cd mkdir packages mkdir trac_sites mkdir install_files
Install Python:
http://python.org/download/releases/2.5.4/
cd ~/install_files wget http://python.org/ftp/python/2.5.4/Python-2.5.4.tgz tar -zxf Python-2.5.4.tgz cd Python-2.5.4 ./configure –prefix=$HOME/packages make make install
Create or edit your .bash_profile in your home directory:
cd
In .bash_profile enter:
export PYTHONPATH=”$HOME/packages/lib/python2.5/site-packages” export LD_LIBRARY_PATH=”$HOME/packages/lib” export PATH=”$HOME/packages/bin:$PATH”
save and then at the prompt enter
source ~/.bash_profile cd which python
verify that the response indicates that the python in your home packages directory is being used:
{path to your home}/packages/bin/python
Install SWIG:
cd ~/install_files wget http://downloads.sourceforge.net/swig/swig-1.3.31.tar.gz tar zxf swig-1.3.31.tar.gz cd swig-1.3.31 ./configure –prefix=$HOME/packages –withpython=$HOME/packages/lib/python2.5 make make install
Install Subversion:

My hosting service already has subversion 1.4.2 installed. Unfortunately it was not compiled with the python bindings required for Trac, so if this is true in your case as well, you’ll have to build subversion yourself.
cd ~/install_files wget http://subversion.tigris.org/downloads/subversion-1.5.5.tar.gz wget http://subversion.tigris.org/downloads/subversion-deps-1.5.5.tar.gz tar zxf subversion-1.5.5.tar.gz tar zxf subversion-deps-1.5.5.tar.gz
I found that in order to get the python bindings to compile successfully, I had to build neon myself before subversion.
cd subversion-1.5.5/neon ./configure –enable-shared –prefix=$HOME/packages –with-libs=$HOME/packages –with-ssl make make install cd .. ./configure –prefix=$HOME/packages PYTHON=$HOME/packages/lib/python2.5 –with-swig=$HOME/packages/bin/swig –with-neon=$HOME/packages –without-berkeley-db make make install
Create a Subversion repository and setup SSH access:
Navigate to a directory that you want to hold your repository and type (substituting your repository name where you see {reposName}):
svnadmin create {reposName}
Create an entry in the repository for the trac project. I like using the project/trunk, project/tags, project/branch structure for each project. To set this up easily, create a temp directory outside of the repository:
cd
mkdir tmpdir
cd tmpdir
mkdir ProjectName
mkdir ProjectName/trunk
mkdir ProjectName/branches
mkdir ProjectName/tags
svn import . file:///{path to your home}/{path to your repository} –message ‘Initial repository layout’
>
Now your subversion repository is ready to go, but it still requires a few tricks to get it to work via ssh since, at least in my case, I’m using a new version of svn that creates repositories that are not compatible with the host-installed svnserve. Ssh by default uses the host-installed svnserve. If you create a subversion repository with a new version and access itvia ssh without the following steps, you’ll likely get a “version 3 expected version 2 error”.
There is more information on using this technique here:
http://subversion.tigris.org/faq.html#ssh-svnserve-location
http://svn.collab.net/repos/svn/trunk/notes/ssh-tricks
To ensure your ssh access uses your compiled svnserve you need to create a public/private key pair you’ll use exclusively for using ssh with subversion. There are a few articles on how to do this here:
http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter8.html
http://linux-sxs.org/networking/openssh.putty.html
Do not enter a password for this subversion-only key:
cd ssh-keygen -t dsa -f /.ssh/examplekey_id
Creates examplekey(private key file) and examplekey.pub (public key file) into the home/.ssh folder. Open the public key and copy the contents into a line in a file in the same folder called ‘authorized_keys’. Create this file if it doesn’t exist. Now in front of the entry you just copied into the file, enter:
command=”{path to your home}/packages/bin/svnserve -t”
When a user connects via ssh, this command specifies that the local svnserve you just built should be used. Now go back to the .bash_profile you created in your home directory on the server above
and add an entry that points to the private key file created above:
export SVN_SSH=”ssh -i $HOME/.ssh/examplekey_id”
Now setup a connection with your local subversion client using the examplekey to connect. There are some directions for how to do this here:
TortoiseSVN using Putty
If you can connect to the subversion server without an error, the hardest part of this installation is behind you.
Install SetupTools:
cd install_files wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py2.5.egg#md5=fe67c3e5a17b12c0e7c541b7ea43a8e6 sh setuptools-0.6c9-py2.5.egg –prefix=$HOME/packages
Install Genshi:
wget http://ftp.edgewall.com/pub/genshi/Genshi-0.5.1.tar.gz tar zxf Genshi-0.5.1.tar.gz cd Genshi-0.5.1 python setup.py install –prefix=$HOME/packages
Install the MySql Python bindings:
cd ~/install_files wget http://downloads.sourceforge.net/mysql-python/MySQL-python-1.2.2.tar.gz tar zxf MySQL-python-1.2.2.tar.gz cd MySQL-python-1.2.2 python setup.py install –prefix=$HOME/packages
Build the subversion python bindings:
You may see libtool linker warnings on the make swig-py step. They don’t seem to have a noticable impact.
cd ~/install_files/subversion-1.5.5 make swig-py
Test with:
make check-swig-py
If everything passes:
make install-swig-py cd ~/packages/lib/python2.5/site-packages echo $HOME/packages/lib/svn-python > subversion.pth ln -s ~/packages/lib/svn-python/libsvn ln -s ~/packages/lib/svn-python/svn
Test with:
python -c “from svn import client”
You should have no errors.
Install Trac and create a project:

wget http://ftp.edgewall.com/pub/trac/Trac-0.11.1.tar.gz tar zxf Trac-0.11.1.tar.gz cd Trac-0.11.1 python setup.py install –prefix=$HOME/packages
Substitute your project name for {ProjectName} below. Using the information from the database you created earlier, your database connection string for the project will be:
mysql://databaseUser:password@servername/databasename
The path to the repository will be:
{path to your home}/{path to your repos}
Now you’re ready to set up the trac project:
cd
trac-admin ~/trac_sites/{ProjectName} initenv
Answer the questions, supplying the database connection string and repository path. When the site is set up, you should get a “Congratulations” message.
Now set up a user with permissions for the project:
trac-admin ~/trac_sites/{ProjectName}
permission add admins TRAC_ADMIN
permission add {username} admins
exit
trac-admin ~/trac_sites/{ProjectName} deploy ~/packages/share/trac
Setup a trac web directory:
Create the directory in your web space that you want to utilize for web access to your trac project and create an .htaccess file with one line:
DirectoryIndex index.fcgi
Create the index.fcgi file with (substituting the project name and home paths):
#!/bin/bash
export HOME=”{path to your home}”
export TRAC_ENV=”$HOME/trac_sites/{ProjectName}”
export PYTHONPATH=”$HOME/packages/lib/python2.5/site-packages”
export PATH=”$HOME/packages/bin:$PATH”
export LD_LIBRARY_PATH=”$HOME/packages/lib”
Make sure the index.fcgi and trac.fcgi files have the right permissions:
chmod 755 index.fcgi cd ~/packages/share/trac/cgi-bin/ chmod 755 trac.fcgi
Now you should have a web-accessible trac installation. You can improve your site by following the directions for pretty urls and static mapping here Natmaster.com.
I also opted to use the following plug-ins:
AccountManager Plugin:
http://www.trac-hacks.org/wiki/AccountManagerPlugin
for 0.11:
passwords:
cd
mkdir b
htpasswd -c ~/{path to password file} {username}
cd trac_sites/{ProjectName}/conf
Now edit the trac.ini file, adding the following sections:
components]
trac.web.auth.LoginModule = disabled
acct_mgr.web_ui.LoginModule = enabled
acct_mgr.web_ui.RegistrationModule = disabled
acct_mgr.htfile.HtPasswdStore = enabled
[account-manager]
; configure the plugin to store passwords in the htpasswd format:
password_store = HtPasswdStore
; the file where user accounts are stored
; the webserver will need write permissions to this file
; and its parent folder
password_file = ~/{path to password file}
TOCMacro:
http://trac-hacks.org/wiki/TocMacro easy_install –prefix=$HOME/packages http://trac-hacks.org/svn/tocmacro/0.11
IniAdmin Plugin:
http://trac-hacks.org/wiki/IniAdminPlugin easy_install –prefix=$HOME/packages http://trac-hacks.org/svn/iniadminplugin/0.11
Now your trac site should be ready to go with subversion fully integrated.
Here are some articles I found along the way that I found helpful:
- http://joemaller.com/2008/01/29/how-to-install-subversion-on-a-shared-host/
- http://www.shaftek.org/blog/2008/02/28/installing-subversion-and-trac-on-1and1-shared-hosting/
- http://www.flipturn.org/TracOnDreamhost.html
- http://natmaster.com/articles/installing_trac_0.10.php
troubleshooting:
- http://forums.apisnetworks.com/archive/index.php/t-273.html
- http://guide.apisnetworks.com/index.php/Suexec
- http://trac.edgewall.org/ticket/6827
putty:

Thanks! I love this tut, will use it to set mine up. I use 1&1’s shared hosting, so this makes things way easy.
Step for InstallSwig should be:
./configure –prefix=$HOME/packages –with-python=$HOME/packages/lib/python2.5/
notice the –with-python