Edgewall Software

Version 67 (modified by anonymous, 16 years ago) ( diff )

Trac on Ubuntu

These instructions were written for a fresh install of Ubuntu. This documentation suggests performing custom install when installing Ubuntu to create a base system without an X server or other graphical niceties. These instructions, however, should work reasonably well if you already have Ubuntu installed or you have performed a full install.

Breezy users: See comments below for some of the problems encountered.

Dapper users: should work fine with the following instructions.

Note: For an alternative Ubuntu experience, using apache and configuring for multiple projects, see TracUbuntuMultipleProjects

Also see: https://help.ubuntu.com/community/UbuntuTracHowto

Installation

1. Install Software Packages

To install Trac on your system, install the trac and libapache2-svn packages:

sudo apt-get install trac apache2 libapache2-svn

2. Create the Trac Environments Directory

You'll need a directory for Trac's environments to live that should be writable by the default Apache user:

sudo mkdir /var/lib/trac
sudo chown www-data:www-data /var/lib/trac

If you put your environment somewhere else, make sure to note that and use that location in the appropriate places in the next step.

3. Setup Apache2

Next, create a new Apache-2 virtualhost by saving the following as /etc/apache2/sites-available/trac :

<VirtualHost *>
        ServerAdmin webmaster@localhost
        ServerName trac.example.com
        DocumentRoot /usr/share/trac/cgi-bin/
        <Directory /usr/share/trac/cgi-bin/>
                Options Indexes FollowSymLinks MultiViews ExecCGI
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        Alias /trac "/usr/share/trac/htdocs"

        <Location /trac.cgi>
            SetEnv TRAC_ENV "/var/lib/trac/YourProjectNameHere"
        </Location>

        DirectoryIndex trac.cgi
        ErrorLog /var/log/apache2/error.trac.log
        CustomLog /var/log/apache2/access.trac.log combined
</VirtualHost>

Note: If you get errors later that pertain to environment look at SetEnv TRAC_ENV. You can also use SetEnv TRAC_ENV_PARENT_DIR "/var/lib/trac" to host multiple projects.

You also need to uncomment the AddHandler line in /etc/apache2/apache2.conf so that the Trac CGI program will be executed:

# To use CGI scripts outside /cgi-bin/:
#
AddHandler cgi-script .cgi

Now, disable the default virtualhost, enable the Trac virtualhost, and restart Apache2:

sudo a2dissite default
sudo a2ensite trac
sudo  /etc/init.d/apache2 reload 

If you are going to want to login, you're going to need authentication. I added the following to my virtual host file to get this to work:

        <Location "/trac.cgi/login">
            AuthType Basic
            AuthName "Trac"
            AuthUserFile /etc/apache2/dav_svn.passwd
            Require valid-user
        </Location>

This will share the password with your subversion install. You'll also need to grant each user rights using trac-admin.

Alternately, you can use htpasswd to create an htpasswd file, and point AuthUserFile at that location.

4. Creating Environments

I installed my Subversion repository at /var/lib/svn/YourProjectNameHere. So I did a quick starting config of subversion with the following commands:

sudo mkdir /var/lib/svn
sudo mkdir /var/lib/svn/YourProjectNameHere
sudo mkdir /tmp/YourProjectNameHere
sudo mkdir /tmp/YourProjectNameHere/branches
sudo mkdir /tmp/YourProjectNameHere/tags
sudo mkdir /tmp/YourProjectNameHere/trunk
sudo svnadmin create /var/lib/svn/YourProjectNameHere
sudo svn import /tmp/YourProjectNameHere file:///var/lib/svn/YourProjectNameHere -m "initial import"
sudo rm -rf /tmp/YourProjectNameHere

Some permissions changes and an apache restart are now needed:

sudo chown -R www-data /var/lib/svn/YourProjectNameHere
sudo chown -R www-data /usr/share/trac
sudo apache2 -k restart

Test by web-browsing to http://servername/svn/YourProjectNameHere

If you see a simple web page which says Revision 1: / and lists branches, tags, and trunk, your Subversion install is up and running!

Here's what to do if you see 404 Not Found

Check you Subversion installation, specifically /etc/apache2/mods-available/dav_svn.conf and make sure you really have a valid configuration. Still having problems see Ubuntu SVN documentation

Now let's finish the Trac install (but don't go on to Trac install until you have the above working properly).

I put my trac environment at /var/lib/trac/YourProjectNameHere. Of course you could use any other path or name - something a little more descriptive of your project would probably be a good idea. First I ran these commands:

sudo mkdir /var/lib/trac
sudo trac-admin /var/lib/trac/YourProjectNameHere initenv
sudo chown -R www-data /var/lib/trac/YourProjectNameHere

The "trac-admin" command shown above prompted me to enter:

  • the project name (YourProjectNameHere)
  • the path to svn repository (/var/lib/svn/YourProjectNameHere)
  • the path to the Trac templates directory (/usr/share/trac/templates)

… then it prints out a bunch of stuff. If there are no errors you should now be able to surf to your Trac site at http://servername/trac.cgi

At the time I did my install, there was one glitch in the Ubuntu Universe Trac installer. It doesn't install the neo_cgi.so file needed in the python2.4 directory space. So when I surfed to my Trac site, I got the error ImportError: No module named neo_cgi. I was able to fix this by symlinking the python2.3 version like so:

sudo ln -s /usr/lib/python2.3/site-packages/neo_cgi.so /usr/lib/python2.4/site-packages/neo_cgi.so

Voila! Your Trac system & website should be up and running.

Comments & Suggestions

  • Celebrate with beer.

mod_python Install

The above instructions are for a CGI-based install. For a simple mod_python install, within your existing Virtual Host:

apt-get install libapache2-mod-python

Follow steps 1 & 2 above. For step 3, here's simple config (this would go inside your existing Virtual Host definition). You also shouldn't have to do any of the other stuff in step 3.

    <Location /trac>
        SetHandler mod_python
        PythonHandler trac.ModPythonHandler # For Breezy++ use: PythonHandler trac.web.modpython_frontend 
        PythonOption TracEnv /var/lib/trac
        PythonOption TracUriRoot "/trac"
    </Location>

For more complex mod_python configs, see TracModPython

You will also need to modify the settings in /etc/apache2/mods-available/dav_svn.conf

<Location>
    # Uncomment this to enable the repository,
    DAV svn

    # Set this to the path to your repository
    SVNParentPath /var/lib/svn
</Location>

Note: You must declare SVNParentPath. The installed .conf files usually just say SVNPath. You need SVNParentPath or else you will get 'Could not open the requested SVN filesystem' errors.

Now, follow the Subversion setup instructions in Step 4 (just the Subversion setup - you don't have to do the rest). Next,

sudo chown -R www-data /var/lib/svn/YourProjectNameHere
sudo /etc/init.d/apache2 restart

Then set up the Trac environment.

sudo mkdir /var/lib/trac
sudo trac-admin /var/lib/trac/YourProjectNameHere initenv
sudo chown -R www-data /var/lib/trac/YourProjectNameHere

Now, you should be able to access Trac at http://youserver.name/trac

Problems

I'm using a fairly standard installation of Breezy on my laptop.

After running through the above instructions, when navigating to http://trac… I got an error stating that it couldn't find a valid Trac environment.

Solution: Modify the /etc/apache2/sites-available/trac file from:

        <Location /trac.cgi>
            SetEnv TRAC_ENV "/var/lib/trac"
        </Location>

to

        <Location /trac.cgi>
            SetEnv TRAC_ENV_PARENT_DIR "/var/lib/trac"
        </Location>

Next, download and install trac_0.9.3-1ubuntu1_all.deb. All the necessary dependencies should've been installed when you tried installed trac_0.8.4.

Error: cannot find /var/lib/trac/VERSION

This can be fixed with the solution above, and allows for multiple projects without re-editing this file:

        <Location /trac.cgi>
            SetEnv TRAC_ENV "/var/lib/trac"
        </Location>

to

        <Location /trac.cgi>
            SetEnv TRAC_ENV_PARENT_DIR "/var/lib/trac"
        </Location>

If you only have one project, the below solution could also be used.

I had to modify my trac virtualhost from

        <Location /trac.cgi>
            SetEnv TRAC_ENV "/var/lib/trac"
        </Location>

to

        <Location /trac.cgi>
            SetEnv TRAC_ENV "/var/lib/trac/YourProjectNameHere"
        </Location>

to have it function properly.

If you're using the mod_python setup above, use CamelCase on the PARENT_DIR parameter:

<Location /trac>
        SetHandler mod_python
        PythonHandler trac.web.modpython_frontend
        PythonOption TracEnvParentDir /var/lib/trac
        PythonOption TracUriRoot "/trac"
</Location>

yielded a working trac installation for me.

Ubuntu 7.04 Feisty AMD64

Ubuntu 7.04 Feisty Fawn does not properly install python-clearsilver for the AMD64 version. This is a known bug https://launchpad.net/ubuntu/+source/clearsilver/+bug/86685.

To summarise the work around:

Install the build dependencies
$ sudo apt-get build-dep python-clearsilver
$ sudo apt-get install python-dev

Download the 0.10.4 version (as it contains fixes for python2.5)
$ wget http://www.clearsilver.net/downloads/clearsilver-0.10.4.tar.gz
$ tar xzvf clearsilver-0.10.4.tar.gz

Edit the configure files as listed by Antonio Censi above

Build the new version
$ cd clearsilver-0.10.4
$ ./configure --with-python=/usr/bin/python2.5
$ make
$ sudo make install

Enjoy!

Ubuntu 5.04 "Hoary"

Ubuntu universe and Hoary Backports only have Trac 0.8 available at this writing. The Edgewall 0.8.4 debian packages specifically require the python2.3-subversion package, which makes installing on Hoary quite painful, as only python2.4-subversion is available without going directly to old debian repos. :( Are 2.3 Python packages really strictly required?

Current Ubuntu 0.8 package does seem to work fine without the neo_cgi problem mentioned above, however.

Solution: trac 0.8.4-1ubuntu1 is currently in Ubuntu Breezy. As the dependencies didn’t change and are coverable by the packages in Hoary, one can simply grab the package from the archive and (provided all of the dependencies are fulfilled) simply

sudo dpkg -i trac_0.8.4-1ubuntu1_all.deb

Ubuntu 4.10 "Warty"

Ubuntu needs versions of python-sqlite and clearsilver that aren't available on Warty (see #468 & #1104). You will need to upgrade to the Hoary release or later.

Note: See TracWiki for help on using the wiki.