] > Natmaster.com - Installing Trac
July 22, 2006

December 21, 2006Please refer to my updated guide to install the latest version of Trac. (This guide only covers Trac 0.9.6)

Introduction

Assumptions

This guide was made primarily to help DreamHost customers setup Trac. However, the setup is generic enough, that with only little modification, this guide can be applied to any shared-hosting setup running the Apache webserver. To work, you will need access to shell, and have basic understanding of text editing in shell. Dreamhost provides python2.3, and easy subversion repository setup - so these are assumed to already be in place.

Also, because I do not like the login hack described on the DreamHost Trac Wiki, I have assumed that you will install one of the login plugins. However, if you have access to the Apache setup file and do not wish to use a login manager, you can use the account setup method outlined in the Trac wiki.

Python

I found installing a local copy of python to be unnecessary, as the extra modules can be installed in the trac's lib path. To assure access to these libs, the PYTHONPATH environment variable must reference the aforementioned path.

Environmental Variables

  • Add this to ~/.bash_profile:

    export PYTHONPATH="$HOME/packages/lib/python2.3/site-packages" export LD_LIBRARY_PATH="$HOME/packages/lib" export PATH="$HOME/packages/bin:$PATH"
  • source ~/.bash_profile

Installation

Setup

I recommend making a special directory for the install files and packages; this makes it easier to manage, and you can delete the entire directory of install files at the end. I used ~/packages and ~/install_files personally, and will be using them throughout these instructions - so if you want to use another directory, just replace all references.

  • cd
  • mkdir install_files
  • mkdir packages
  • mkdir trac_sites

Install Trac (0.9.6)

  • cd ~/install_files
  • wget http://ftp.edgewall.com/pub/trac/trac-0.9.6.tar.gz
  • tar zxf trac-0.9.6.tar.gz
  • cd trac-0.9.6
  • python setup.py install --prefix=$HOME/packages

Install Clearsilver (0.10.3)

  • cd ~/install_files
  • wget http://www.clearsilver.net/downloads/clearsilver-0.10.3.tar.gz
  • tar zxf clearsilver-0.10.3.tar.gz
  • cd clearsilver-0.10.3
  • sed -i "s@/usr/local/bin/python@/usr/bin/env python@g" \ scripts/document.py PYTHON_SITE=`/home/{username}/packages/bin/python -c \ "import sys; print [path for path in sys.path if \ path.find('site-packages') != -1][0]"` \ ./configure --with-python=/home/{username}/packages/bin/python \ --prefix=$HOME/packages \ --disable-ruby --disable-java --disable-apache --disable-csharp --disable-perl
  • make
  • make install

Install SQLite (3.3.6)

  • cd ~/install_files
  • wget http://www.sqlite.org/sqlite-3.3.6.tar.gz
  • tar zxf sqlite-3.3.6.tar.gz
  • cd sqlite-3.3.6
  • ./configure --prefix=$HOME/packages
  • make
  • make install
  • ln -s $HOME/packages/bin/sqlite3 $HOME/packages/bin/sqlite

Install PySQLite (2.3.2)

  • cd ~/install_files
  • wget http://initd.org/pub/software/pysqlite/releases/2.3/2.3.2/pysqlite-2.3.2.tar.gz
  • tar zxf pysqlite-2.3.2.tar.gz
  • cd pysqlite-2.3.2
  • In setup.py, change
    include_dirs = [] to include_dirs = ['$HOME/packages/include']
    and
    library_dirs = [] to library_dirs = ['$HOME/packages/lib']
  • python setup.py build
  • python setup.py install --prefix=$HOME/packages

Install SWIG (1.3.29)

  • cd ~/install_files
  • wget http://dl.sourceforge.net/sourceforge/swig/swig-1.3.29.tar.gz
  • tar zxf swig-1.3.29.tar.gz
  • cd swig-1.3.29
  • ./configure --prefix=$HOME/packages --with-python=/usr/bin/python
  • make
  • make install

Install Subversion (1.3.2)

  • cd ~/install_files
  • wget http://subversion.tigris.org/downloads/subversion-1.3.2.tar.gz
  • tar zxf subversion-1.3.2.tar.gz
  • cd subversion-1.3.2
  • ./configure PYTHON=/usr/bin/python --prefix=$HOME/packages \ --with-swig=$HOME/packages/bin/swig --without-berkeley-db \ --with-ssl --with-zlib
  • make
  • make install
  • make swig-py
  • make install-swig-py
  • cd ~/packages/lib/python2.3/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 it with python -c "from svn import client" (No errors should result.)

Setup Trac Environment

  • trac-admin $HOME/trac_sites/{your trac project id} initenv

    ("{your trac project id}" can be anything you like. Putting all your Trac environments in your trac_sites directory allows for simpler backup!)

    You will be asked for

    • Project Name: {Whatever you want}
    • Database connection string: {Accept the default (just hit return)}
    • Path to repository: /home/{yourusername}/svn/{your svn project id}
    • Templates directory: {Accept the default (just hit return)}
  • trac-admin $HOME/trac_sites/{your trac project id} will put you into interactive mode. You can issue a simple help at the prompt to see what you can do. There are lots of administrative actions in interactive mode that can make your life a little easier than it would be if you always had to go through the WebAdmin interface.

    You should add at least one user with admin powers. To do this, in interactive mode:

    • permission add admins TRAC_ADMIN
    • permission add {username} admins
    • exit (to quit interactive mode)

    During interactive mode, permission list should show the new users on the list.

Make Trac Web Accessible

  • cd ~/{my.domain.name}
  • Make index.cgi (make sure to set the permissions so the webserver can read it - 775):

    #!/bin/bash export HOME="/home/{username}" export TRAC_ENV="$HOME/trac_sites/{your trac project id}" export PYTHONPATH="$HOME/packages/lib/python2.3/site-packages" export PATH="$HOME/packages/bin:$PATH" export LD_LIBRARY_PATH="$HOME/packages/lib" exec $HOME/packages/share/trac/cgi-bin/trac.cgi
  • and index.fcgi (make sure to set the permissions so the webserver can read it - 775):

    #!/bin/bash export HOME="/home/{username}" export TRAC_ENV="$HOME/trac_sites/{your trac project id}" export PYTHONPATH="$HOME/packages/lib/python2.3/site-packages" export PATH="$HOME/packages/bin:$PATH" export LD_LIBRARY_PATH="$HOME/packages/lib" exec $HOME/packages/share/trac/cgi-bin/trac.fcgi
  • Then set the default by editing .htaccess:

    DirectoryIndex index.cgi You can change this to index.fcgi once you have everything setup. (Fcgi is faster, but you won't notice changes until a day later.)

Prettiness

Pretty URLs

Setup static mapping

This allows the common static files (images, CSS, javascript, etc) to be accessed directly, rather than mapping through the cgi script. (This makes Trac faster, while providing compatibility with the prettiness.)

  • cd ~/{domain name}
  • mkdir chrome
  • ln -s $HOME/packages/share/trac/htdocs ./chrome/common
Setup Rewrite Rule

Edit .htaccess located in the {domain name} directory DirectoryIndex index.cgi Options ExecCGI FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.cgi/$1 [L] </IfModule> This will prefix any failed request with index.cgi (to run it through Trac).

Hack the Trac base_url

This sets any links Trac generates to start from the base, rather than the file that processed the generation. (/whatever, instead of index.cgi/whatever)

  • cd $HOME/packages/lib/python2.3/site-packages/trac/web
  • Backup the original cgi_frontend.py in case you want to revert. cp cgi_frontend.py cgi_frontend.py.backup
  • Edit cgi_frontend.py, change
    self.cgi_location = self.__environ.get('SCRIPT_NAME')
    to
    self.cgi_location = os.path.dirname(self.__environ.get('SCRIPT_NAME'))

Plugins

Setup Tools

We'll be using this to install the other plugins; so it is necessary to install this to follow my steps.

  • cd ~/install_files
  • wget http://peak.telecommunity.com/dist/ez_setup.py
  • python ez_setup.py --prefix=$HOME/packages

WebAdmin Plugin

  • cd ~/install_files
  • wget http://trac.edgewall.org/attachment/wiki/WebAdmin/TracWebAdmin-0.1.1dev_r2765-py2.3.egg.zip?format=raw TracWebAdmin-0.1.1dev_r2765-py2.3.egg
  • easy_install --prefix=$HOME/packages TracWebAdmin-0.1.1dev_r2765-py2.3.egg
  • Now tell trac to load the plugin by editing $HOME/trac_sites/{your trac project id}/conf/trac.ini and adding to the components section: [components] webadmin.* = enabled

AccountManager Plugin

NOT COMPATIBLE WITH DbAuth

This will make the htpasswd login method much more pleasing. New users can register on their own using the site, and they can change their passwords if necessary. This also allows login via form, rather than the HTTP authentication.

  • cd ~/install_files
  • svn co http://trac-hacks.org/svn/accountmanagerplugin/0.9
  • mv 0.9 accountmanagerplugin
  • cd accountmanagerplugin
  • python setup.py bdist_egg
  • cd dist
  • easy_install --prefix=$HOME/packages *.egg
  • You must add an initial user, to create the initial trac.htpasswd file:
    htpasswd -c ~/trac_sites/trac.htpasswd {username}
    You'll then enter the password twice.
  • Now tell trac to load the plugin by editing $HOME/trac_sites/{your trac project id}/conf/trac.ini and adding to the components section: [components] trac.web.auth.LoginModule = disabled acct_mgr.* = enabled [account-manager] password_format = htpasswd password_file = /home/{your username}/trac_sites/trac.htpasswd

DbAuth Plugin

NOT COMPATIBLE WITH AccountManager

Makes more sense than the normal login method. However it does not support new user registration like AccountManager, rather, you are required to enter all users in manually using sqlite. Because of this, I use AccountManager instead.

  • cd ~/install_files
  • svn co http://www.trac-hacks.org/svn/dbauthplugin
  • cd ./dbauthplugin/0.9
  • python setup.py bdist_egg
  • cd dist
  • easy_install --prefix=$HOME/packages *.egg
  • cd ../install
  • cp dbauth.db ~/trac_sites
  • chmod 775 ~/trac_sites/dbauth.db
  • Now you need to add some users; you'll have to do this manually. You'll probably want to add the same username(s) as you setup earlier.
    • sqlite ~/trac_sites/dbauth.db
    • INSERT INTO trac_users VALUES ('all', 'username', 'passwd', 'email@email.com'); INSERT INTO trac_permissions VALUES ('all', 'username', 'admins');
    • .quit
  • Now tell trac to load the plugin by editing $HOME/trac_sites/{your trac project id}/conf/trac.ini and adding to the components section: [components] trac.web.auth.* = disabled dbauth.* = enabled #trac.userdir.* = enabled # only if you want to use this [central] database = /home/{your username}/trac_sites/dbauth.db envroot = /home/{your username}/trac_sites/{your trac project id}

Cleanup

Now that you have everything setup the way you want, you can go ahead and delete all those setup files, and switch to fast_cgi

Delete setup files

Since you won't be using those setup files after you're done, if you don't want all those setup files to take up hard drive space, you can delete them.

  • cd
  • rm -rf install_files

Switch to fcgi

If you are using 'Pretty URLs'

Change .htaccess to direct to index.fcgi, rather than index.cgi: DirectoryIndex index.fcgi Options ExecCGI FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.fcgi/$1 [L] </IfModule>

Otherwise

Just change the .htaccess DirectoryIndex to index.fcgi DirectoryIndex index.fcgi

References